Recently, I started working on a Drupal 6 project and needed it set up on my dev environment, which is currently Ubuntu 12.10. No problem: grab the code from our svn server, a copy of the database, set up a local vhost and… see all the errors on a very broken Drupal. Hrmm. Works fine on the server but not my computer. This D6 plus CiviCRM site needed an older version of PHP. I could downgrade my PHP but that would mess up the other projects I’m working on. So, I came to the obvious conclusion for these sorts of technical challenges: I need a time machine. Simply travel back in time to where the entire stack on my dev site is compatible with the project, make the changes, then return to today and sort out the resulting confusion in the billing department. (“You did this 9 months ago and are billing for it now?”)
Well that might not work for everyone, especially outside of science fiction, so let’s explore some other tools that achieve similar ends to that of time travel. Actually, open source is quite good at travelling into the past. Most projects will have links to download previous versions of their software. Git, and any source code management system, provide a way to go back to any previous state of the code. When travelling back though, keep in mind you still need today’s security patches.
But time travel alone doesn’t solve the problem. I need an alternate universe where pieces from different times can coexist. I figure if two Spock’s from two different times can exist together in the same place then it just might be possible for Drupal too. Linux Containers to the rescue.
LXC – LinuX Containers
LXC is a lightweight virtualization method. Very similar to OpenVZ, although with less features, it allows you run multiple linuxes in containers on a single host. We make good use of OpenVZ containers at CivicActions for our hosting but it might be overkill for a dev environment. If you are using Ubuntu and don’t need the more advanced features of OpenVZ, I recommend LXC as it is much easier to install.
More information: https://help.ubuntu.com/12.04/serverguide/lxc.html
For my dev environment I set up Ubuntu 12.04 of the past which has the PHP I need.
# sudo apt-get install lxc
# sudo lxc-create -t ubuntu -n drupal6 — -r precise
# sudo lxc-start -d -n drupal6
# sudo lxc-list
Then install LAMP stack and set up Drupal. Mission accomplished: two different Drupal stacks coexisting on my dev machine. I access my dev site via an IP address on the virtual subnet that LXC provides.
Tomorrow is Yesterday
LXC helps us travel into the past but, like any science fiction fan, I also want to live in the future. Say I have an Ubuntu 12.04 LTS server but want the cutting edge. I would try something like this:
# sudo lxc-create -t ubuntu -n ubuntu1304 — -r raring
But I would get this error because 12.04 doesn’t know about 13.04: E: No such script: /usr/share/debootstrap/scripts/raring
Easily fixed. All we need is a symlink:
# cd /usr/share/debootstrap/scripts
# sudo ln -s gutsy raring
Now we’re raring to go. Try the lxc-create command again and it should build the container. As of this writing it is not quite released (https://wiki.ubuntu.com/RaringRingtail/ReleaseSchedule) but I’ve found 13.04 to be stable these last weeks.
Linux containers provide an excellent way to separate out tasks and purposes. When familiar with the lxc-* commands, it is a convenient way to manage multiple servers and easily experiment with new things such as the next Ubuntu release. And it’s just asking for Drupal 8 so stay tuned for my next blog.