Skip to content Get in touch

Contact form

Developing with WordPress – part 1: Varying Vagrant Vagrants

This is the start of a new series: Developing with WordPress. We will focus more on the tools and workflows for a faster and more effective way on developing your WordPress projects. Every week there will be a new topic we discuss and today we kick things off with an introduction to local development with a virtual machine, and in particular Varying Vagrant Vagrants.

Local Development

When you first start developing with WordPress you probably have a local environment running with your PHP, your database and your webserver configured. You create a virtual host, download the latest stable WordPress version and off you go. That works fine as long as you are alone and don’t have too many projects to maintain. But the problems start happening as soon as you start to work together with someone else on the same project: “it doesn’t run on my machine” is an often heard problem that many times is caused by differences in local environments: a different PHP version, a different MySQL version, a different webserver altogether (Apache vs Nginx, for example), we’ve all been there. Here is where a virtual machine together with Vagrant comes in.

Virtual Machine and Vagrant

If you are not aware yet on what a virtual machine is I suggest you to read up on that first here. As you can guess, a virtual machine can be used for local development. But if you and your team all use different configurations of a virtual machine then you will still run into the same problems mentioned above. It would be better to have a set of rules that everyone uses so you all have the same configuration. That is what Vagrant does for you: you declare a set of rules and with that Vagrant sets up your virtual machine. Vagrant needs 2 files for this: a Vagrantfile (yes, that’s one word) that tells Vagrant what kind of hardware the virtual machine needs and one (or more, but at least one) provision file that tells Vagrant what to do on the virtual machine. So if you set up a Vagrant configuration and share that with your team then you all are using the exact same configuration. And that leads us to the main topic of today: Varying Vagrant Vagrants

Varying Vagrant Vagrants

Instead of reinventing the wheel and coming up with a great Vagrant configuration for your WordPress development needs you can reap the fruits of someone else’s labor. Varying Vagrant Vagrants offers you an excellent starting point for your WordPress development. Varying Vagrant Vagrants (VVV from now on) sets up your virtual machine with a configuration ideal for WordPress development and adds some useful extras. A standard VVV installation sets up Nginx, MariaDB, PHP as the basic needs for your WordPress site to run, but also comes with WP-CLI, Node.js, Mailcatcher, Composer, memcached and various other tools, which we will all discuss in this series later. On top of that VVV also gives you two WordPress installations from the start, one that is the latest stable version and one that is the latest dev version, so you can start experimenting right away.

Installation

So let’s talk installation. How do you set this all up? Well, the first things you need is the latest version of VirtualBox and Vagrant.

VirtualBox: follow the instructions here.

Vagrant: follow the instructions here.

VVV requires a few extra vagrant plugins, you can install them with exectuing the following command in your terminal:

$ vagrant plugin install vagrant-hostsupdater vagrant-triggers vagrant-vbguest

Once those are installed we can move on with installing VVV. This can be done easily via Git. I have my VVV installation in my Sites folder but you can set it up the way you prefer.

Run the following command in your terminal once you are in the folder where you want VVV to be:

$ git clone -b master git://github.com/Varying-Vagrant-Vagrants/VVV.git vvv

This will create the vvv directory in the current folder and that is all there is to it. Those steps all have to be done only once, you are now ready to start using VVV.

Vagrant up

There is plenty that Vagrant can do but the only command you need to start with your VVV is vagrant up

Open your terminal and go inside your VVV folder:

$ cd ~/Sites/vvv

Then, just type:

$ vagrant up

And you should see your terminal doing a lot of stuff. The first time it will take a while because everything needs to provisioned, but eventually you will see in the terminal that all is done and you can start using VVV.

Go in your browser to http://vvv.test to open the dashboard. Here you can confirm that everything is up and running and you will see some info about your installation.

Next steps

This was the introduction to setting up VVV for developing with WordPress. By now you should have a working setup of VVV running on your machine. Feel free to experiment with the WordPress installations that come default with VVV: http://local.wordpress.test/ for the latest stable version and http://src.wordpress-develop.test/ for the latest dev build. Username and password in both cases is “admin” / “password”

Next week we’ll show you how to create your own WordPress sites in VVV and how to connect to the database from outside the virtual machine.

More about this topic

Other thoughts

More thoughts