Vlad - The Vagrant LAMP Ansible Drupal development box

Slice 1 Created with Sketch.

I’ve been using local development environments for years to work on websites. At one points I even setup some Phing scripts to create Apache hosts and databases locally so that I didn’t have to keep adding them myself.

When I was first introduced to Vagrant I liked the idea of supplying a box with a project so that people could work on it without having to reconfigure their system for each project. What was missing was a good provisioning tool that wasn’t difficult to understand. I had looked at Puppet and Chef but they were just too complex and after a couple of hours of looking into each one I still wasn’t sure about how they worked.

After being introduced to Ansible I decided that this was the tool I needed and set about creating a Vagrant development environment that would suit my day-to-day development and maintenance of Drupal websites. The product of this development is Vlad, the Vagrant LAMP Ansible Drupal development box. I chose to use the name Vlad as it was short, easy to say, and wasn't as long as saying 'that Vagrant Ansible Drupal development thingy'.

I have been using Vlad for a few weeks now and have started packaging it with my Drupal builds, especially where the build has some complex element like a custom Solr setup. I have noticed a few things that I needed to make copying Vlad into those projects easier and have committed them back into the project.

To get started with Vlad you need to install the following components:

  • Virtualbox - The system that runs virtual machines.
  • Vagrant - The virtual machine manager.
  • Ansible - A provisioning tool.
  • Sudo Pasword - The sudo password is required for some actions during the setup process.

After downloading Vlad just go into the Vlad directory and use the command ‘vagrant up’. You will see Vagrant set up the box and then Ansible provision it with the needed software.

Vagrant integrates nicely with NFS and Vlad will link a directory called ‘docroot’ in the project with the directory /var/www/sites/docroot on the Vagrant guest. This means that the docroot can contain the source code for your site without having to manage git repos on the guest.

After setting up Vlad you can access the box using the address 'http://www.drupal.local/'. Vlad uses a local Ansible task to set up your local hosts file, so that you don’t have to do anything to see this address. The default IP address given to the guest box is 192.168.100.100.

Rather than just set up a Apache2, PHP, and MySQL trio I decided to include include a few different technologies. Some are development tools to help with inspecting how a site is running, and others are common tools in use in live setups. Here is the full list of available technologies that Vlad contains, and what they are used for.

Apache2
A HTTP server that delivers web pages, listening on port 8080.

PHP
PHP is installed as a client library and as an Apache module so that Drupal can run through Apache. A number of configuration options (e.g. post_max_size) are set when installing PHP.

MySQL
A database server that is used quite commonly with Drupal sites. Some best practice security measures have been actioned on the server, like removing the test database and securing the root user. The default database credentials are ‘vlad’ for the user and ‘wibble’ for the password.

Varnish
A reverse proxy server that is used as a cache mechanism for Apache page requests. Varnish listens on port 80, but it can be bypassed by directly accessing Apache on port 8080.

Git
A version control system. It is not advisable to commit and push from Vagrant itself but has been included so that you can pull down libraries (perhaps via Drush make) with ease.

Drush
Drush is a command line Drupal tool that allows you to interact with Drupal sites. The Drush install also includes the 'site audit' and 'hacked!’ modules, which allows the analysis of Drupal sites.

Xdebug
This is a commonly used PHP debugging tool. It has been set up to allow remote debugging so you can use an IDE like PHPStorm or Netbeans to run through the code. To use the debugger, point your IDE at the Vlad box IP address (192.168.100.100) and use port 9000, you may also need to trigger it through the browser. Profiling has also been enabled and can be activated by appending XDEBUG_PROFILE=true to the end of the URL.

XHProf
The XHProf PHP extension can be used to garner detailed statistics about PHP code execution. You can view XHProf at the address http://xhprof.drupal.local, but in order to see what is going on with your application you need to append "?_profile=1" to the end of the URL in this way http://www.drupal.local/?_profile=1.

Munin
This is a performance monitoring tool that I have written about previously. This is a node component that doesn’t do much on it’s own, but will provide you with graphs of current activity if you plug it into a Munin server.

SASS
SASS is a CSS compilation language that is used on some Drupal themes (e.g. Omega4). Also installed are with SASS are Compas, Susy, and Respond-to.

Mailcatcher
Mailcatcher is installed as a default mail server for PHP and will therefore intercept all email sent through any website installed on the Vagrant guest. You can access MailCatcher via the URL http://www.drupal.local:1080.

Sendmail
Sendmail is an SMTP server that manages mail. By default it is not installed when setting up Vlad, but it can be easily enabled via the Ansible playbook playbooks/site.yml by uncommenting out the appropriate line.

Memcached
Memcached is a key/value server that is commonly used by Drupal sites to speed up cache loading. All necessary PHP modules have also been included on Vlad.

Adminer
Adminer is a lightweight database administrator and can be viewed at the address http://adminer.drupal.local/. It has been included with some simple settings that allow you to immediately login to the application when you open it. There is also a custom stylesheet included in order to make it look a little different from other Adminer installs.

Solr (Version 4)
This is a search engine that has been growing on popularity on Drupal platforms in recent years. I wasn’t originally going to include Solr as part of this project, but I found myself using it more and more often and decided that I should include it just in case. Solr is run through Apache Tomcat, a Java friendly HTTP server, and can be viewed at the address http://www.drupal.local:8081/solr.

Part of the reason I started developing this box was in order to have a ready made development environment for any version of Drupal, with the hope of seriously starting to contribute to Drupal 8. As a result I don’t make the assumption of installing Drupal onto the box, although I have made installing Drupal 7 quite easy. To install Drupal 7 on the box log in (using 'vagrant ssh') and run the script located at /var/www/drupal_install.sh. This will install a brand new Drupal 7 site, with the admin username of 'admin' and the password of 'password'.

Vlad has been created with Ansible roles and as such each sub system can be turned off by just commenting out the appropriate line in the Ansible playbook file at playbooks/site.yml. The good thing about using Ansible with this project is that the roles can easily be adapted to a real server to provision it accordingly.

To adapt Vlad to your own project just open the main Vagrantfile and edit the few lines of configuration at the top. This will be everything you need to create a new box, with a different IP and web address. Other configuration options are held in the file 'group_vars/all', which is where the PHP variables, MySQL ports and ini settings can be set.

As I said before I have now been using Vlad as a template for all new builds, and has proved an invaluable tool in getting up and running quickly. It also allows me to have a very similar local setup to that of the server I will be deploying the code to, which can cause headaches from time to time.

To download Vlad go the the Vlad repo page and click on the download link on the right hand side. This will get you the latest version of the system. I am really looking for people to test out the system and feed back to me with ideas for improvements, packages they want to be included, or documentation that will help users get up and running.

If you are looking for a Vagrant development box for Drupal that uses Puppet then take a look at Mike Bell's DrupalDev nginx.

Comments

An interesting post. One suggestion: add a 'Drupal' tag to the metadata so that it could be picked up in the Category sidebar navigation under the Drupal heading. It seems odd that it does not show up under there.
Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
2 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.