快快樂樂用
Homestead
chengwei @ Laravel 台灣 (2014.12.18)
!
陳正瑋 @ 得寬科技 DevOps
!
一步一步的往DevOps之路前進...
內容概要
‧Introduction
‧Installation & Setup
‧Customized
Laravel Homestead
official, pre-packaged Vagrant "box"
VAGRANT
VAGRANT
‧Command Line Tool.
‧Tool for building complete
development environments.
‧Manage and provision 

Virtual Machine.
Host OS , Guest VM
!
Host OS
(PC, Mac …)
Host OS , Guest VM
!
Host OS
!
!
!
Guest VM
!
!
!
Guest VM
Host OS , Guest VM
!
Host OS
!
!
!
Guest VM
!
!
!
Guest VM
Synced folder Synced folder
Code
Host OS , Guest VM
!
Host OS
!
!
!
Guest VM
!
!
!
Guest VM
DB (3306) http (80)
33060 8000
VAGRANT
+
Vagrantfile
BOX
VAGRANT
+
Vagrantfile
BOX
Base Image
Setting、Config…
Homestead
+
Customized Vagrantfile
VAGRANT BOX
+ Ruby scriptsHomestead.yaml
laravel/homestead
(Box Version 0.2.1)
‧ Ubuntu 14.04
‧ PHP 5.6
‧ HHVM
‧ Nginx
‧ MySQL
‧ Postgres
‧ Node (With Bower, Grunt, and Gulp)
‧ Redis
‧ Memcached
‧ Beanstalkd
‧ Laravel Envoy
‧ Fabric + HipChat Extension
Box Included Software
homestead 1.x ->2.0
+
Customized Vagrantfile
VAGRANT BOX
1.x
+
homestead CLI
VAGRANT BOX
Customized Vagrantfile
2.0
homestead 1.x ->2.0
vagrant COMMAND
homestead COMMAND
~/.composer/vendor/bin
homestead 1.x ->2.0
Folder
Global
~/.homestead
homestead 1.x ->2.0
vagrant up
homestead up
?
vagrant up
scripts/homestead.rb
config.vm.box = "laravel/homestead"
Create VM VM provision
Read Homestead.yaml
vagrant up
homestead 1.x
Read Vagrantfile
homestead up
Read ~/.composer/……/homestead/Vagrantfile
Read ~/.homestead/Homestead.yaml
homestead up
vagrant up
~/.composer/……/homestead/scripts/homestead.rb
config.vm.box = "laravel/homestead"
homestead 2.0
Create VM
Run ~/.homestead/after.sh
VM provision
DEMO
vagrant up
homestead up
&
Installation & Setup
Laravel Homestead
Step
‧Install VirtualBox
‧Install Vagrant
‧Add Box (laravel/homestead)
‧Install Composer (非必要)
‧Install Homestead
On OS X
just piece of cake
On Windows
more difficult
Install Homestead On Windows
‧64-bit guests need hardware-virtualzation
enabled in the hosts bios. (VT-x / AMD-V)
‧If running Windows as host you must
make sure hyper-v or xp mode is not
enabled on the host. MS does not play
well and wants it all.
‧CMD Tool (e.g. Bash tool, Cmder)
‧PHP, SSH ……
Install Homestead On Windows
Download VirtualBox
Install Homestead On Windows
Install VirtualBox
Install Homestead On Windows
Download Vagrant
Install Homestead On Windows
Install Vagrant
Install Homestead On Windows
vagrant box add laravel/homestead
Install Homestead On Windows
Install Homestead 2.0
Install Homestead On Windows
https://www.youtube.com/watch?v=-73VP4AW2ec
Laravel Homestead 2.0 On Windows
Setup homestead.yaml
Setup homestead.yaml
Homestead 2.0
先下指令 homestead init
Homestead 1.x
直接編輯 homestead.yaml
再下指令 homestead edit
~/.homestead/Homestead.yaml
Setup homestead.yaml
2.0
Setup homestead.yaml
ip、memory、cpu
key -> login VM
synced folders (share folders) | host -> guest VM
Nginx site conf
create DB
Setup homestead.yaml
default
setup memory >= 1024
Setup homestead.yaml
default
setup
Setup homestead.yaml
host folder
Setup homestead.yaml
Guest VM folder
Setup homestead.yaml
Nginx site conf
!
server {
!
server_name local.demo;
!
}
Setup homestead.yaml
Nginx site conf
!
server {
!
root /home/vagrant/demo_site/public
!
}
Setup homestead.yaml
synced folder 1
synced folder 2
nginx site conf 1
nginx site conf 2
Setup homestead.yaml
synced folder
Nginx site conf
Setup homestead.yaml
DB 1
DB 2
Setup homestead.yaml
DB 1
DB 2
DB 1
DB 2
Provision
vagrant up --provision
vagrant provision
homestead up --provision
*sites
!
*databases
change Homestead.yaml
Provision
vagrant up --provision
vagrant provision
homestead up --provision
rebuild DB
homestead 2.0
DEMO
homestead up
--provision
Customized Homestead
自己的 homestead 自己客製
Homestead
+
Customized Vagrantfile
VAGRANT BOX
Homestead
Customized Vagrantfile
VAGRANT BOX
Customized
Homestead
VAGRANT BOX
laravel/homestead
Homestead
VAGRANT BOX
Replace
laravel/homestead
Other Boxes
Boxes ?VAGRANT CLOUD
https://vagrantcloud.com/boxes/search?utf8=%E2%9C%93&sort=&provider=&q=homestead
使⽤用者應注意,使⽤用別⼈人建置之 Box 必有⾵風險,請⾃自⾏行判斷⼩小⼼心使⽤用
自行打包
https://docs.vagrantup.com/v2/virtualbox/boxes.html
使⽤用者應注意,打包需花費時間與硬碟容量,打包前請做好事前評估
自行從零建立Box
https://github.com/laravel/settler
參閱官⽅方 git hub 建⽴立屬於⾃自⼰己的 homestead box
Rewrite Vagrantfile
Homestead 2.0
~/.composer/vendor/laravel/homestead/scripts/homestead.rb
Homestead 1.x
folder/scripts/homestead.rb
Rewrite Vagrantfile
Rewrite Vagrantfile
Rewrite Vagrantfile
Customized Vagrantfile
~/.homestead/after.sh
homestead 2.0
Customized Vagrantfile
https://github.com/mcuyar/station
station
station
homestead station
+
BOX: laravel/homestead
homestead
Customized Vagrantfile
+
BOX: laravel/homestead
station
Customized Vagrantfile
Customized Vagrantfile
‧Read Vagrant Docs
‧Use Other Vagrant Provisioner
‧Rewrite Vagrantfile
DEMO
use after.sh
use my Box
use station
結語
今夜、ご注文はどっち?
Homestead 2.0Homestead 1.x
Customized

快快樂樂用Homestead