Screen Shot 2013-12-19 at 2.07.23 PM

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

Curtis McHale

Posts Twitter Google+

Curtis is a web designer/developer specialized in WordPress eCommerce development on WooCommerce. You can get in touch with him about projects on SFNdesign.
My Blog is 4 Times Faster Than Your Blog

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

  1. First, this is awesome. Thank you.

    I just finished watching your 3 vagrant screencasts and they answered all my practical questions about getting WP up and running on VVV. I tried a couple time before but crashed and burned each time. The bigest sticking points being VVV is essentially a single vagrant instance w/ it’s own www directory. This point previously wasn’t clear to me and it made no sense to me to spin up a vagrant box for each site/plugin (but most vagrant users seem to. In my world it does make sense to have a few for different configs (nginx/apache, memcache/opcode/xcache/apc, PHP versions, etc), but not 50 for 50 sites.

    I currently have 50+ sites in MAMP and it wasn’t clear to me how to move one (or all) of them into Vagrant. In previous attempts I thought I’d need to create 50 vagrant boxes. Now, thanks to the screencasts, thing make sense and I’ve figured out how to do that sensibly.

    I do have two questions having just watched this screencast: 1) I’m surprised you haven’t scripted all that file editing, why not? 2) I’m surprised you’re strategy for creating DBs is to add them to init rather than just create them directly, is there a reason for that?

    • I’m glad it cleared things up for you.

      My file script-fu is week so I simply haven’t tried.

      I simply feel more comfortable adding them to the init. The other side affect is that if they are in the init, and you have a DB in the database/backups folder of the exact same name it will auto-import the database as you run the VM. Makes setup easier for other devs or designers I’m onboarding and sets up WP Migrate DB Pro for them with all the URL translations.

  2. It seem inconceivable to me that someone so comfortable with the command line doesn’t have matching script-fu skills, but I get it, neither do I!

    I figured this VVV Auto Site Setup was a good starting point. https://github.com/varying-vagrant-vagrants/vvv/wiki/Auto-site-Setup
    Should I manage to digest that and then get it a working script built where I can just pass it a domain name and it creates the rest (which is what I’m hoping for) I’ll put it on GH and link to it.

    One thing stumbled with is that It _seems_ like init-custom.sql only run on provisioning (not halt/up). Maybe it’s just me.

    One other thing was I had assumed I could move the MySQL folders (.opt & .frm files) from Mamp Pro to Vagrant, but they don’t seem to work. They show up, but the tables are corrupt somehow (when I select them Sequal Pro throws errors and complains). Seems like I HAVE to SQL dump them to move them for now, but the trick of dumping them to /backups and then them being auto-imported sounds slick.

    • I really just fake my command line fu, fake it well.

      I’ll have to dig in to the auto site setup as well and see what I can get going, when I have time which doesn’t seem like it’s going to be any time soon.

  3. Thanks for this Curtis. I have recently started using VVV and command line etc. I got an additional domain working after realising I needed to run: vagrant provision as opposed to just vagrant up to get the install rocking.

  4. I’ve found https://github.com/aliso/vvv-site-wizard to be a great script to automate the site setup

    • Yes I have heard of it but haven’t used it before. I rally should take the time to try it.

      • I’m playing /w it currently I’m liking it so far. I was able to migrate a site from MAMP to vagrant in around 5 min with little issue