Posted on December 19, 2013 by Curtis McHale

Adding a new domain to an existing VVV (Vagrant) box

I’ve already written 2 posts on Vagrant, specifically using VVV to run your WordPress development boxes.

  1. Working with WordPress and Vagrant – Basics
  2. Vagrant and Custom Domains with WordPress

The second post did show you how you could add a custom domain to a Vagrant install, but didn’t specifically call out my day to day workflow for using Vagrant.

My VVV workflow

Most of the time I use the same VVV box for all projects. So all theme builds and plugin builds…To add a new site to an existing VVV box I use the instructions you’ll find below.

If I have to build a WordPress MU site I usually build a custom VVV box that has all the domains mapped and the dabatase setup for the user. Then the next developer just has to clone our VVV box and add the hosts file entries to get the project running.

Adding the new domain

Our first step is to open you terminal program and change directory (cd) to the VVV install you want to add a domain to. From the root type cd config/nginx/sites.

Here you should find a few files ending in the .conf extension. Copy one and rename it to screencast.wpthemetutorial.com.conf then open it in your editor of choice. You’ll need to change 2 lines.

  1. On line 28 change the server name to match the domain you want to see the site at: server_name screencast.wpthemetutorial.com;
  2. On line 31 you should see the path to the install location in your www directory: root /srv/www/wptt-screen;

Now we need to go back to the root of the Vagrant box and go in to our database directory by typing cd database.

Then open init-custom.sql so we can add our custom database commands. I copy the last entry and pasted it below. I’ll change all our values to swptt. I don’t think it’s worth making it super long/hard since this is not a live web sever and anyone that can access this has access to your machine.

CREATE DATABASE IF NOT EXISTS `swptt`;
GRANT ALL PRIVILEGES ON `swptt`.* TO 'swptt'@'localhost' IDENTIFIED BY 'swptt';

Now we need to go back to the root of the VVV box and type cd www to get to the web directory on our server. Here we need to move all the WordPress files in to their proper spot in the wptt-screen folder.

You can do this by typing cp -rv wordpress-default/ wptt-screen.

Finally I want to remove the wp-config.php file that was in the copied WordPress install. Type rm -rf wptt-screen/wp-config.php and the wp-config.php file will be gone.

Now you need to type vagrant up to start the VVV box.

Once Vagrant comes up all you should need to do is type screencast.wpthemetutorial.com in to your browser and then follow the WordPress install steps.

Screencast