Using vagrant

Post on 17-Jan-2017

179 views 3 download

Transcript of Using vagrant

Using VagrantCuong 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

GETSTARTED

Installation

Enabled Virtualization mode on Host machineInstall Oracle’s VirtualBoxhttps://www.virtualbox.org/wiki/Downloads Install Vagrant (for Windows, Mac, Linux)https://www.vagrantup.com/downloads.html

BoxCreate a box $vagrant box add [name] [location

of basebox]

$vagrant box add laravel/homestead

https://atlas.hashicorp.com/boxes/searchInitialise a project$vagrant init laravel/homestead

ConfigurationUsing the Vagrantfile that be created after run initialise projectVagrant.configure("2") do |config|

//…

End

ConfigurationDefine hostnameconfig.vm.hostname = "develop-server"

Define static IPconfig.vm.network "private_network", ip: "192.168.37.10"

Define synced folderconfig.vm.synced_folder ".", "/var/www"

ConfigurationDefine virtual machine configurationconfig.vm.provider "virtualbox" do |v|

v.gui = false v.memory = 2048 v.cpus = 1end

ConfigurationDefine Provisionconfig.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 devSHELL

CommandsRun vagrant$vagrant up

Shutdown vagrant$vagrant halt

Destroy project box$vagrant destroy

Reload vagrant$vagrant reload

Connect vagrant$vagrant ssh

PackageStart with a Base box, customize it as neededRun 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

ProblemThe problem comes from shares. Using VirtualBox native sharing is horribly slow. You can use Windows sharing (SMB), but that is also painfully slow

FIXInstall WinNFSD Plugin vagrantvagrant plugin install vagrant-winnfsd

Details at: https://github.com/winnfsd/vagrant-winnfsd

FIXAdd 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 !