Last time we overviewed virtualization and its advantages for Drupal developing. It was all theory stuff, so I’m sure you’re itching to actually get a VM going. Let’s get started.
Choosing a Virtualization Provider
The first task is to choose a virtualization provider. While there are many to choose from, I recommend Oracle Virtualbox for development environments. Virtualbox is open source, and available for download for Windows, Mac, and Linux.
Like most virtualization providers, Virtualbox installs kernel-level drivers that will require a system restart. Furthermore, you will experience a brief network interruption during installation as virtual network devices are created on your system. This is normal and only lasts a few seconds.
In addition to Virtualbox, we’re going to make building and managing our VMs easier using Vagrant. Virtualization providers are designed to be a general as possible. They don’t provide a simple command line interface, or integration with automatic server configuration tools such as Ansible or Chef. Vagrant fills that gap making things considerably easier for developers.
You can install Vagrant manually, or by using an alternative package manager such as Chocolatey on Windows, or Homebrew with Cask on Mac OS X.
Linux users can install Vagrant using their distro’s default package manager such as apt-get, yum, or pacman. Note that many package managers do not list Virtualbox as a hard requirement and will allow you to install even when there’s no virtualization provider on your system!
Getting VMs (the Lazy Way)
At this point, you have enough to start building VMs for your development environment. Building a VM is very much like installing a new OS on hardware. It can be time consuming and dull. Fortunately for us, a considerable community has gathered around Vagrant, providing us when many ready to use VMs and easy tools to build new ones customized to our needs.
Vagrantbox.es -- Premade but General
Vagrantbox.es is a one-stop-shop for ready-to-run vagrant VMs. Simply scroll through the list and find one that suits your needs. Most of the boxes provided on the site are intended to provide infrastructure in the cloud sense -- a running VM with the system tools necessary to customize it to your use. This isn’t a bad choice if you need a basic VM and you’re willing to install additional software.
PuPHPet -- Point and Click Custom VMs
PuPHPet is very much the opposite of Vagrantbox.es. Instead of just picking a VM off of the shelf, PuPHPet provides a web interface that allows you to build a customized LAMP, vagrant enabled VM. With the click of a checkbox you can add PhpMyAdmin, XDebug, Drush, and a number of other utilities.
PuPHPet is great if you’ve used VMs before and you want things configured in a particular way. It takes more technical knowledge and previous experience with UNIX-like operating systems. PuPHPet is great for building “starter VMs” that you later customize and publish for use by your entire team.
Vagrant Drupal Development (VDD) -- Out of the Box Drupal
Vagrant Drupal Development (VDD) is a project on Drupal.org, and is considered the standard vagrant VM for Drupal work. It’s based on Ubuntu headless, and includes PhpMyAdmin, Drush, and XDebug out of the box. It’s the most straightforward out of the bunch for virtualized Drupal development environments, and comes with extensive documentation on the project page. This article will use VDD.
VLAD and FFW’s Own Efforts
The downside to VDD is it is basic. For some client sites, you need advanced mail handling abilities, caching, and Apache Solr integration. VLAD provides these facilities out of the box, but the VM requires additional post-deploy configuration. FFW is also working on our own Vagrant image inspired by VLAD. Keep watching our blog for more news!
Cloning and Upping your VM
Since VDD is a most Drupal specific and the easiest to set up, we’ll use that for the rest of this article.
First, create a directory for the image configuration to live in:
Then, clone the VDD repo into the directory:
git clone --branch 8.x-1.x http://git.drupal.org/project/vdd.git .
Finally, start the VM:
When starting the VM for the first time, vagrant will download the Virtualbox disk image from a remote source. This can take several minutes depending on your network. Then, vagrant runs configuration tools to make sure that the image is configured correctly. The vagrantfile in our my-vdd directory instructs vagrant on how to configure the VM. This configuration only occurs on the first deploy, and does not need to be rerun once the VM instance has been provisioned.
Once running, you can visit the VM in your web browser by going to http://192.168.44.44
Sharing your VM
The vagrantfile is key to sharing the VM. You put this file under version control, rather than the disk image files of the VM itself.
When you issue vagrant up, the vagrantfile can specify a remote source to download the VM, be it on your corporate network or on the public internet. Vagrant will then reconfigure the VM in the same way each time. This is why upping for the first time takes a significantly longer time; vagrant instructs the CI tool to download, install, and configure the system software including Apache, MySQL, and PHP as the base VM does not have them installed.
Creating vagrantfiles is a bit of an art form. This is why sites like PuPHPet exist, making creating them much easier.
We now have the tools (and the talent) to start using our new virtualized development environment. Next time we’ll perform two key pieces of configuration and then upload our site onto the VM so we can start developing!