Quick & Easy Dev Environments with VagrantPresentation Transcript
Quick & Easy Dev Environments with Vagrant MemphisPHP.org 3/26/13 Tonights Sponsor:
About Vagrant"Vagrant is a tool for building completedevelopment environments. With an easy-to-use workflow and focus on automation, Vagrantlowers development environment setup time,increases development/production parity, andmakes the "works on my machine" excuse arelic of the past."-http://www.vagrantup.com/about.html
What can Vagrant do for me?● Easily create environments without waiting for an Operating system install● Easily configure pre-built boxes or build your own● Share packaged environments with coworkers or a team of developers● Ensures everyone is developing against the same target environment.● Portable - move environments from machine to machine
Lets get startedInstall VirtualboxInstall Vagrant (Windows users may need to restart after)Start an admin command lineenter vagrant -v in the command line.Aquire a vagrant box http://www.vagrantbox.es/vagrant box add box_name URL/Path
Create a project foldermkdir vagrant-memphisphpcd vagrant-memphisphpvagrant initA file Vagrantfile is created, edit this file andchange the value of config.vm.box to the nameof the box you added earlier.
Configure network / portsuncomment the config.vm.network line and letsset up port 9000 to forward to port 80 on theVMconfig.vm.network :forwarded_port, guest: 80,host: 9000
Fire up the VM!Simply run vagrant upOnce the command has finished, the box willbe running in the background.Now we need to configure ssh so we canremote into the box.vagrant ssh
SSH + Windows = Putty+ PuttyGenOn windows, this will give a warning that it cannot find anexecutable ssh. What we need to do here is open putty,configure 127.0.0.1:2222 with the private key it generatedhere: C:/Users/halo/.vagrant.d/insecure_private_keyYou will need to use Puttygen to generate the key for puttyto use. The user name will be vagrant
Post Lamp config...Once this script completes you should be ableto view http://localhost:9000/ and see thedefault CentOS apache page.
Shared FoldersBy default vagrant shares the project directorywith the guest VM mounted at /vagrant You canadd your own shares via the Vagrantfile.
Shutting Down / ReloadingWhen you need to shut down or halt the VMyou can simply use vagrant halt.If you need to restart to reload the Vagrantfileconfig, use vagrant reloadYou can also vagrant suspend to suspend theVM.
Destroy!To completely wipe the VM you can vagrantdestroy.Then simply run vagrant up again to reimportthe box and start over.
Sharing is caring... or something...vagrant packageThis will shutdown the VM and create adistributable package of the VM to you canshare / deploy to a dev team.C:Usershalovagrant-memphisphp>vagrant package[default] Attempting graceful shutdown of VM...[default] Clearing any previously set forwarded ports...[default] Creating temporary directory for export...[default] Exporting VM...[default] Compressing package to: C:/Users/halo/vagrant-memphisphp/package.box
Links & Further ReadingVagrant: www.vagrantup.comVagrant Boxen:www.vagrantbox.esCentOS: www.centos.org