Vagrant WordPress

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.

What Vagrant is (and why it’s an excellent tool for WordPress development) 👨🏻‍💻

The Vagrant home page.

At its core, Vagrant is a tool for virtual machine management. You can provision machines using VirtualBox, VMware, and even online services, such as Amazon Web Services (AWS).

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.

Some examples of Vagrant WordPress boxes.

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.

  1. Install VirtualBox and Vagrant
  2. Install a Vagrant WordPress box
  3. Test your new WordPress local installation

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:

vagrant -v

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.

The VCCW homepage.

VCCW comes with Ubuntu, Git version control, the latest version of WordPress, WP-CLI, PHP 7, MySQL, Apache, and much more. In other words, it packs in everything you need.

To get started, you’ll need two things:

  1. The VCCW Vagrant box
  2. 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):

cd nameofthenewdirectory

When you’re inside the environment in the command line, type in the following:

vagrant up

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:

  1. http://vccw.test
  2. http://192.168.33.10

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:

Connecting to your VCCW box via SSH.

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!

Conclusion 🏁

Vagrant is far from the only tool you can use for local WordPress development. Other popular options are:

However, Vagrant WordPress environments are so lightweight and easy to reproduce they’re perfect for collaboration.

Once you have a Vagrant WordPress environment set up and running, you can use it for staging purposes, testing, or get to work on a new project locally.

Do you have any questions about Vagrant WordPress environments? Let’s go over them in the comments section below!

2 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
dav
February 17, 2024 8:34 am

Followed the instructions, the server is up and running with wordpress, but can’t login because vccw.test domain isn’t working. How to solve this?

dav
February 17, 2024 9:29 am
Reply to  dav

This is an old Xenial project, I’ve subsequently installed VVV, but you can still muck around. Solution would be something like: vagrant plugin install vagrant-hostsupdater or vagrant plugin install vagrant-goodhosts

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (itโ€™s free)!