Vagrant

A WordPress local development environment with Vagrant

VagrantI’ve used XAMPP as my WordPress local development environment for the last couple of years, but as I’ve done a lot of development on the Smart Insights site recently, it’s been frustrating me that my development environment doesn’t match with the live server. So I started looking into alternative solutions.

I’ve recently migrated Smart Insights to Synthesis after considering most of the premium WordPress managed hosting companies such as WPEngine and Pagely. Synthesis run their platform on virtualized server instances running NGINX with a configuration tailored specifically toward speeding up WordPress. It’s fast – blindingly so if you use the custom W3 Total Cache rules they give.

Meanwhile, XAMPP is standard PHP/mySQL running on Apache. No optimisation for WordPress. No specific configuration for caching or anything else.

What this means is that I’m developing locally on a system that’s completely different to the live server, which isn’t a great idea. Chances are at some point, something that seems to work completely fine on my WordPress local development environment will fail to work on the live server when I launch. Not often, of course – WordPress pretty much runs on anything. But if you can negate the risk of it happening by mirroring the live server on your local development environment, it makes sense that you should!

A better solution for WordPress local development environments

A few months ago another developer introduced me to Vagrant;

Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.

To do its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. Then, industry-standard provisioning tools such as shell scripts, Chef, or Puppet, can be used to automatically install and configure software on the machine.

Virtualization is nothing new, of course, it’s been around for many years. What’s great about Vagrant is that once you’ve created your environment, you can package it up in such a way that it can be fully scripted and becomes portable. If you want to create a certain development server configuration that pulls a fresh copy of your client site from GitHub and sets it up every time you fire up the server, you can. If you want to import the latest version of the live database at the same time, you can do that too.

It changes the way you think about working locally. Instead of your own LAMP environment that you maintain separately to your development code, the two become entwined. When you need to work on a client site, just fire up the instance of their server on your local machine and get working straight away. If you want to bring another developer in to work with you, just give them a copy of the instance and they’re good to go immediately – no messing around with set up and configuration and dealing with inconsistencies between their local environment and yours.

The issue? Getting Vagrant set up and tweaked in the way you want it takes a lot of time.

Varying Vagrant Vagrants

Thankfully, after searching around to see if anybody in the WordPress community had considered using Vagrant for local WordPress development environments, I found that Jeremy Felt had not only considered it, he’d created a Vagrant configuration that was pretty much exactly what I needed – a development environment that included Ubuntu 12.0.4 with Nginx, PHP-FPM, MySQL and Memcached out of the box. This is exactly why I love the WordPress community so much!

Varying Vagrant Vagrants is an exploration into the world of of Vagrant and how it can help to make development efficient and in sync with production systems. It replaces the common MAMP or XAMPP setups that we have become familiar with and ensures that all members of the team can develop in the same environment for a project without worrying about the operating system on their local machine.

More at Evolving WordPress development with Vagrant

After setting it up and spending an hour tweaking, I now have a Smart Insights development instance that I can fire up within two minutes that pretty closely matches the live server environment.

Jeremy’s next step is to try and push the managed WordPress hosting companies to give a configuration for their hosting, so us developers can truly match the live server set up. Really hope he’s successful with this!

What’s next

I’m still figuring out the detail of tweaking the Vagrant config Jeremy provides. I’d ideally like the instance to pull a fresh copy of the Smart Insights database every time it’s started – as this is one of the biggest issues with WordPress development – how to keep your local development synchronised. Getting this to work would mean you don’t have to worry about it, and it’d save a lot of time.

I’d love to hear from anyone else using Vagrant for their WordPress local development environment – how are you finding it and what benefits has it brought you over MAMP/XAMPP?

Published by

Stu Miller

Web consultant and specialist, WordPress developer and PHP developer based in Leeds, UK. 15 years experience in architecting web sites and applications. Co-founder and Technical Director of SmartInsights.com, formerly the same of First 10 Digital

One thought on “A WordPress local development environment with Vagrant”

Leave a Reply