Vagrant has been on my radar for a while now (thanks to @jr261) and has been high on my list of things that I must try out.

Well, thanks to Jeremy Quinton‘s excellent talk at this years PHP Conference I finally got around to giving it a spin.

Overview

Vagrant (through the power of virtualisation)  allows you to create a fully functioning development stack (operating system, web server, database server, etc…) tailored specifically for a project. This reduces the time it takes to install all the required software/libraries locally on a developers machine and also ensures consistency both between developers and with staging/production servers.

Once the initial Vagrant configuration has been completed a simple config file (Vagrantfile) is committed to your source-code repository. Each developer simply has to execute the vagrant up command and within minutes they will have their own fully functioning development environment – simple!

At Switch Systems our development team works on both Linux and Windows machines which has in the past caused headaches when certain Linux libraries have no Windows alternatives – the cross platform nature of Vagrant should eliminate these issues in the future.

Configuration

The initial setup turned out to be surprisingly simple. Vagrant’s own setup guide was easy enough to follow and with the help of the v1 docs I even managed to create my own debian 7 box file without issue (feel free to use it for your own projects).

A few tips for anyone starting out:

  • Use NFS support for linux/mac developers, it is much faster! After some extensive googling a Stack Overflow comment explained how to enable NFS only on non-Windows clients, add the following to your Vagrantfile: config.vm.synced_folder ".", "/vagrant", :nfs => !RUBY_PLATFORM.downcase.include?("w32")
  • If you use the private_network mode do not assign your Vagrant machine an IP address ending in X.X.X.1 as this is the IP address that your host computer is assigned, instead start from X.X.X.2!

Vagrant offers a number of ways to configure or “provision” your virtual machine after it boots. The most basic way is to use a simple shell script,  alternatively you can use a dedicated provisioning system such as Puppet or Chef to provide a more configurable and fine-grained way to setup your environment. So far I have found the shell script approach to be sufficient but can see that the flexibility of a provisioner such as Chef would be invaluable as a project increases in complexity.

I can’t recommend Vagrant highly enough to anyone who works across multiple projects or as part of a cross-platform development team – give it a go now!

Now to find some time to learn Chef