On any project, whether you’re a themer, site builder or developer you will need a local development environment to work in. Even if everyone on a project works on the same OS, chances are people will have different versions of Apache MySQL and PHP, different server configuration and not to mention that the local environment will differ from staging and production environments.
In this post, I give a quick overview of how Vagrant and VM's can improve your developer workflow and consistency.
Vagrant is supported on all of the major OSs: Mac, Windows and Linux. For the initial install and setup of Vagrant you only need to install Vagrant itself, and the virtualisation app, VirtualBox which is also open source. Getting started is fairly straightforward: just by typing a couple of commands you have a Linux environment which you can SSH into.
Here's a list of the commands that I commonly use day to day:
- To start the virtual machine for the first time or anytime after halting or destroying: vagrant up
- To halt the virtual machine (this will not remove the environment) : vagrant halt
- Remove the virtual machine environment completely: vagrant destroy -f
- To SSH into the virtual machine: vagrant ssh
For detailed information checkout the Vagrant Command-Line Interface documentation.
Advantages of using Vagrant
No need to worry about local server configuration. No project is the same and on some projects I found that to I had to tweak some settings to make them work properly e.g increase PHP memory, or Apache timeout settings. Using vagrant, I don’t have to that since the dev environment has been configured by a sys admin.
Don’t have to worry about firing up and configuring other services, such as Apache Solr. Most of the projects I work on have Apache Solr Search which a sophisticated search system that interacts with Drupal. For Solr to work on you local environment, you need to launch it in the terminal and configure Solr in Drupal. This is now been taken care of with a Vagrant VM.
Relatively quick to set up an environment on your machine. Whether you're setting up an existing project via MAMP or Vagrant, it still takes time to setup. Vagrant is relatively easy and quick to setup in an automated way.
Don’t need to have a MAMP stack installed. Most developers will have an Apache MySQL PHP stack installed and configured on their machines. But it still takes time to setup. Recently I found that I had to use a replacement machine because mine had died. Setting up Vagrant was much easier than having to install and configure an AMP stack from scratch.
Issues found with Vagrant
Vagrant runs on Virtualbox which is resource heavy, so if you see you’re machine slowing down may need to increase your memory. For VirtualBox system requirements checkout: https://www.virtualbox.org/wiki/End-user_documentation
Very rarely, I find that I have to rebuild vagrant as it doesn’t allow me to connect to it after launching it.
The good news for Drupal themers, is you can run all of your front-end tools (sass, compass, gulp, etc) from your Mac command line, and because your local file system is mounted inside the VM it all just works.
Overall I recommend anyone team that is working across a project to Vagrant. It does make local environment setup and maintenance much easier.vagrant