There are many ways to set up a local development environment to help you test your new WordPress projects. However, a lot of tools are resource-heavy. On the other hand, setting up a more lightweight testing environment manually can get tricky. Using a Vagrant WordPress ‘box’ can offer a good middle ground between the two.
In a nutshell, Vagrant lets you set up testing environments with very little overhead. This means you can run several unique environments side by side using different configurations, even on modest hardware.
In this article, we’ll introduce you to Vagrant environments and how the box system works. Then we’ll teach you how to set up a Vagrant WordPress environment.
Let’s get to work!
- 1 What Vagrant is (and why it’s an excellent tool for WordPress development)
- 2 How to set up a Vagrant WordPress development environment (in 3 steps)
- 3 Conclusion
What Vagrant is (and why it’s an excellent tool for WordPress development)
Vagrant works by you using the command line to set up ‘containers’ or ‘boxes.’ You can then configure and interact with these boxes through the command line, as well as use your favorite text editor, browser, and any other tools you have installed on your computer.
Vagrant environments tend to be very lightweight in comparison to full virtual machines. What’s more, you can quickly set up ready-to-go environments using boxes that other users share – and there are plenty of options to choose from.
The best part of using Vagrant is that it’s easy to share your configuration files or boxes with other team members. This means you can all have identical development environments to work on, even if you use a different operating system (OS) or setup.
When it comes to WordPress, there are a lot of pre-built Vagrant environments you can use. Let’s go over how the process works.
How to set up a Vagrant WordPress development environment (in 3 steps)
As we mentioned, Vagrant is a command-line tool available for Linux, Mac, and Windows. However, there are a few dependencies you’ll need. Let’s start there.
Step 1: Install VirtualBox and Vagrant
Since you’ll use Vagrant locally, you need a program that enables you to set up new virtual machines. VirtualBox is the software Vagrant recommends, and both programs work together out of the box.
First, you’ll want to install the appropriate version of VirtualBox for your OS. Once the software is set up, go ahead and install Vagrant. When you’re done, open the command line and type in the following:
This is a simple test to see if Vagrant is running correctly. If you don’t see a message confirming the current version of Vagrant installed on your system, reboot your computer and try again.
Once you confirm Vagrant is working, it’s time to set up a WordPress environment.
Step 2: Install a Vagrant WordPress box
Instead of setting up a whole environment from scratch, you can get right to work by using a pre-built WordPress configuration. There are a lot of options for Vagrant WordPress boxes, but we recommend you use VCCW, which is an environment built for theme and plugin development.
To get started, you’ll need two things:
- The VCCW Vagrant box
- Its installation files
First, run the following command in your Terminal or equivalent:
vagrant box add vcc-team/xenial64
Now download the latest configurations instructions for your new Vagrant WordPress environment. It weighs less than 20 Kb, which shows how easy it is to replicate environments using Vagrant.
Once you have the files, set up a new local directory for your environment and move the zip file inside. Next, move into this environment using the command line (replacing the placeholder text we’ve used):
When you’re inside the environment in the command line, type in the following:
The vagrant up command tells your new virtual machine to start using the instructions from the file inside its directory. Since this is the first time your machine spins up, it can take a while for Vagrant to set everything up. Subsequent starts will go by much faster.
Once your Vagrant WordPress box is ready, you’ll be able to use the command line again and test if everything is working correctly.
Step 3: Test your new WordPress local installation
Once your VCCW box is up, you should be able to access it from your browser using either of these addresses:
If everything’s working correctly, you’ll be able to log into WordPress using ‘admin’ as both your username and password. This is not a combination we’d recommend under normal circumstances, but for a local testing environment, it’s not a big issue.
As we touched on, VCCW automatically sets up a MySQL database for your local website. To access it, you can go to
127.0.0.1 on port
3306 through your browser. These are the default login credentials:
- Username: ‘wordpress’ or ‘root’
- Password: wordpress
Since Vagrant doesn’t provide you with a visual interface for your virtual machine, you’ll need to rely on SSH to edit any files outside of WordPress.
You can access your box via SSH using either of its URLs as the hostname. Both the username and password will be set as ‘vagrant’ by default:
Once you’re connected to your box, you can make any changes you want to it using the command line. If you don’t feel comfortable editing files in this way, now would be a great time to learn since you have the perfect testing environment to do so!
However, Vagrant WordPress environments are so lightweight and easy to reproduce they’re perfect for collaboration.