In this article, i’m going to show you how to set up a local WordPress development environment with Vagrant. We will be using Vagrant WordPress LEMP created by Trevor Maglione. I prefer using this compared to something like VVV because it is more lightweight (using Puppet to provision the VM rather than a complex shell script), it’s quick to use, and uses the latest technologies. Vagrant WordPress LEMP will install WordPress on top of the following technologies:
- Ubuntu 14.04
- MariaDB (an open source, drop-in MySQL replacement)
- WP CLI
Step 1: Install VirtualBox Vagrant & Plugins
To get started, we need to install VirtualBox. VirtualBox is a free and open source virtualization software backed by Oracle. This is what we’ll be using to create our virtual machines. Go to Virtualbox.org to download & install VirtualBox for your operating system.
Next we install Vagrant. Vagrant is your command line interface to VirtualBox. Vagrant is used to create and provision virtual machines. Go to VagrantUp.com to download & install Vagrant for your operating system.
Once Vagrant is installed, we need to install the Vagrant Hosts Updater plugin to make changes to your hosts file so virtual machines can easily be accessed in your web browser. In your command line type:
`vagrant plugin install vagrant-hostsupdater`
Step 2: Set up Vagrant Project
We’re now ready to launch our first virtual machine:
- Download a version of Vagrant WordPress LEMP here.
- Extract the file
- Rename Vagrantfile.sample to Vagrantfile
- Edit line 16 to the desired name of your development site, for example if you renamed it wptemple you can access the site at http://wptemple.dev/
- On line 30, you’ll need to keep track of the IP address. For the first VM you launch you don’t need to change it, but future VMs can’t have the same IP address, or you’ll have conflicts.
There are other things you can change in this file like the version of Ubuntu, amount of memory, CPUs, WordPress Login, MySQL Login, etc.. but i’ll leave that up to you to discover and modify (at your own risk).
Step 3: Launching the VM
Note: Windows users, please do the following steps in an elevated command prompt or the hosts updater plugin won’t set a URL.
Launching your VM is simple:
- In Terminal/Command Prompt go to the folder where your Vagrantfile is located
- Type `vagrant up`
The first thing that will happen (for first time Vagrant users) is it will import Ubuntu, it should take a couple of minutes. After a few minutes (for Mac/Linux Users) it will prompt you for your password for superuser permissions. This is so Vagrant can modify your /etc/hosts file to point the site you specified in the Vagrantfile to the VMs IP Address. Once that is done, Vagrant will then provision the virtual machine Installing a LEMP stack, PHPMyAdmin, WP-CLI, and then WordPress.
Once it’s done, go into a web browser and type in the name that you specified (in my example, http://wptemple.dev/). You will now see a working WordPress site. The default login credentials are vagrant/vagrant, but could be different if you changed this in your Vagrantfile before provisioning.
And there you have it, a completely functional WordPress development environment. How did the setup go for you?