Using Vagrant for repeatable local web development
What we will do
For the moment, I’ve an idea of use of independent environments, which could be shared between our devs team, which works on Linux and Windows workstations.
So, file ressources could be hosted on parent OS and virtual machine contains real development environment, and the logic is porcessed by the virtual machine, which contains the environment, identic to production server.
The dB is shared between all developers, but each developer has it’s own virtual environment, with files which are shared between guest and host.
Web developer works in a folder which is shared between Vagrant and his host machine. The files are externalized from virtual machine. So the developer could use tools from main OS to get maximum comfort and productivity.
Each developer machine could be accessed from an external location by a web browser.
Each vagrant machine of each developer could be managed from an external location by SSH, to provide maximum of automation.
Introduction to Vagrant concept
There are boxes, real virtual machines models, which You could turn inside Your workstation. You could find a big list of available vagrantboxes [here]. You could use some box, personalize it and distribute it.
It’s a configuration file, it contains information how Your virtual environment will be created, how it will communicates with parent OS.
VM machine creation and use
$ mkdir vagrant_www/www -p $ cd vagrant_www $ echo "<h1>Hello from a Vagrant VM</h1>" > www/index.html $ vagrant init $ vagrant box add precise64 http://files.vagrantup.com/precise64.box $ vagrant up $ vagrant ssh
Vagrant::Config.run do |config| config.vm.box = "precise64" config.vm.forward_port 80, 8080 end
The host web server could be accessed from host http://127.0.0.1:8080/
Internal VM operations
- Install basic LAMP stack
- Change default Apache2 user to vagrant
- Change default vhost to /vagrant/www
- Restart Apache
If You have several developers, You could prepare the Vagrant box, distribute it and run on another workstation.
Package the installation
You could package with Your current Vagrantfile, or create more generic Vagrantfile.pkg for packed box :
$ vagrant package --vagrantfile Vagrantfile.pkg
Recreate the box
On the workstation of another member of Your team :
$ vagrant box add my_box /path/to/the/package.box $ vagrant init my_box $ vagrant up
The code exchange of web projects could be done trough version control system, as git (centralized repository using branches in case when You need).
Puppet and Chef
Great tools to automate package management of Your box.
- Vagrant intro http://docs-v1.vagrantup.com/v1/docs/getting-started/index.html
- Access Vagrant machine from an external location http://stackoverflow.com/questions/12176159/connecting-to-a-vagrant-vm-externally
- Vagrant basics (FR) http://blog.ledez.net/informatique/vagrant-ou-les-vm-pour-les-nuls/ :http://www.vagrantbox.es/