Using Vagrant
Cuong Huynh @cuongdev
AppsCyclone - Workshop - 2016.7.23
WHY
VAGRANT?
Your development and production
environment are not the same!
● Different OS
● Different version (PHP, …)
● Different default configuration files
● Vagrant lowers
development
environment setup time
● Maximizes dev/pro parity
GET
STARTED
Installation
Enabled Virtualization mode on Host machine
Install Oracle’s VirtualBox
https://www.virtualbox.org/wiki/Downloads
Install Vagrant (for Windows, Mac, Linux)
https://www.vagrantup.com/downloads.html
Box
Create a box $vagrant box add [name] [location of
basebox]
$vagrant box add laravel/homestead
https://atlas.hashicorp.com/boxes/search
Initialise a project
$vagrant init laravel/homestead
Configuration
Using the Vagrantfile that
be created after run
initialise project
Vagrant.configure("2")
do |config|
//…
End
Configuration
Define hostname
config.vm.hostname = "develop-server"
Define static IP
config.vm.network "private_network", ip: "192.168.37.10"
Define synced folder
config.vm.synced_folder ".", "/var/www"
Configuration
Define virtual machine configuration
config.vm.provider "virtualbox" do |v|
v.gui = false
v.memory = 2048
v.cpus = 1
end
Configuration
Define Provision
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get update
sudo apt-get install -y whois git
sudo useradd -m -p `mkpasswd password` -s /bin/bash dev
sudo usermod -a -G sudo dev
SHELL
Commands
Run vagrant
$vagrant up
Shutdown vagrant
$vagrant halt
Destroy project box
$vagrant destroy
Reload vagrant
$vagrant reload
Connect vagrant
$vagrant ssh
Package
Start with a Base box, customize it as needed
Run command to package
$vagrant package --output my_box.box
Other users can now use
$vagrant box add my_box /path/to/my_box.box
$vagrant init my_box
$vagrant up
Improve Vagrant on
Windows
Problem
The problem comes from shares. Using
VirtualBox native sharing is horribly slow.
You can use Windows sharing (SMB), but
that is also painfully slow
FIX
Install WinNFSD Plugin vagrant
vagrant plugin install vagrant-winnfsd
Details at: https://github.com/winnfsd/vagrant-
winnfsd
FIX
Add configs
config.vm.network "private_network", type: "dhcp"
config.vm.synced_folder ".", "/var/www", type: "nfs"
Show log (optional)
Config.winnfsd.logging = “on”
After that, reload vagrant to apply new config. ENJOY IT !

Using vagrant

Editor's Notes

  • #2 Vagrant là 1 công cụ xây dựng và quản lý các máy ảo, có thể chạy trên Ubuntu, MacOS và cả Windows. Có thể nói Vagrant đang đứng trên vai những người khổng lồ. Máy ảo được cung cấp bởi các provider là VirtualBox, VMware, AWS,… Các phần mềm được cài đặt sử dụng provisioner đã trở thành quy chuẩn là shell scripts, Chef, Puppet. Điều này giúp cho vagrant có thể quản lý nhiều loại máy ảo khác nhau, tự động cài đặt phần mềm cho máy tính mà không quan tâm đang sử dụng OS hay distribution nào.
  • #9  While it is easiest to download boxes from HashiCorp's Atlas you can also add boxes from a local file, custom URL, etc.
  • #10  While it is easiest to download boxes from HashiCorp's Atlas you can also add boxes from a local file, custom URL, etc.
  • #11  While it is easiest to download boxes from HashiCorp's Atlas you can also add boxes from a local file, custom URL, etc.
  • #12  While it is easiest to download boxes from HashiCorp's Atlas you can also add boxes from a local file, custom URL, etc.
  • #13  While it is easiest to download boxes from HashiCorp's Atlas you can also add boxes from a local file, custom URL, etc.
  • #14  While it is easiest to download boxes from HashiCorp's Atlas you can also add boxes from a local file, custom URL, etc.
  • #15  While it is easiest to download boxes from HashiCorp's Atlas you can also add boxes from a local file, custom URL, etc.