WordPress Development Environment with VirtualBox and Vagrant

Check it out on GitHub

When developing content for WordPress like themes or plugins it is always important to test the results on various server configurations and WordPress versions. Because it doesn’t make fun to run multiple PHP verions locally and it’s too expensive to have several testing machines, it is a good idea to use virtual machines for this job. VirtualBox is a good option because it is free, supports all common operating systems and it is frequently updated.

To not always have to setup a virtual development environment from scratch, there is another great tool: Vagrant. It automates the creation of virtual machines. With the combination of VirtualBox and Vagrant it is very comfortable to work with virtual systems. If one crashes I simpy can start it over. Another great feature is, that I can use my development environment on whatever host machine I work, be it a Mac, Windows or Linux system. VirtualBox and Vagrant are available for those three major operation systems.

Automatically installed WordPress versions

Playing around with Vagrant I stumbled upon the Varying Vagrant Vagrants (VVV) project. It does what I was looking for: building a WordPress development environment with Nginx webserver, PHP 5.4, MySQL 5.5 and some more helpful stuff. It automatically installs the latest stable WordPress version alongside the current beta version. That is great when you develop a WordPress website which will be hosted under the same circumstances. VVV is kind of project focused. For me as a plugin developer it is not completely adequate. I need a server configuration that is found on most webhosters with the minimum requirements for WordPress. This is why I choose to setup my own Vagrant/VirtualBox project inspired by VVV.

In my project I switched back to Apache webserver as it is still the most popular webserver and found on most servers of my customers. Then I need a variety of WordPress version to ensure the backwards compatibility of my plugins. I added a routine to automatically install all major versions beginning with 3.1 up to to 3.5.2 at the time of writing (you can easily add other versions to provision/install-wp-dev.sh). Additionally the trunk (beta version) gets installed too. Vagrant is configured to use Ubuntu precise32 (12.04) by default and the default PHP package which is 5.3.10. One open point on my list remains a configuration with PHP 5.2.4 and MySQL 5.0, the official WordPress minimum requirements.

vagrant

The cool thing is, that all installions share the same wp-content directory (via symlink). So I can put my contents there and can access it from all versions. It is easy to switch betweend the WP version. After the environment is running and the records to the local machine’s hosts file are written, I can open http://wp.dev/3.5.2 in my browser. If I want antother version I just have to change the version part of the URL, like http://wp.dev/3.1 or http://wp.dev/trunk.

Through the possiblity of custom scripts I can configure additional share folders. These are directories on my host machine shared to the virtual environment. My project files reside on my host machine and get shared to the wp-content directory on the virtual server. I can continue my developing work using my favorite PHP IDE with the local project files.

If you are interested in learning more about my WordPress Development Environment, you will find the project on GitHub: https://github.com/ifeelweb/ifwWordPressDevEnvironment There is also a more detailed explanation on how to setup and configure everything.

I hope someone finds it as useful as I do. If you have questions or ideas to improve, please let me know or make a pull request.

Check it out on GitHub

Tags: , , ,

One Response to “WordPress Development Environment with VirtualBox and Vagrant”

  1. Kalen Johnson December 10, 2013 at 06:57 #

    Thanks for posting this, it looks very helpful. i also found that vvv was interesting, but not exactly what I needed for my dev process. So I’ve been searching Google for how other people have set up their WordPress and Vagrant environments.

    I’ll be sure to check out your Github repo. Thanks for sharing!

Leave a Reply

fifteen + ten =