Setting up a WordPress VVV Vagrant Workflow

Using VVV Vagrant as a WordPress local development workflow is a great flexible platform, here’s mine which uses 5 bits of software to create a vagrant box.
VirtualBox,Vagrant, VVV,VVV Dashboard and VV Variable (optional, but still worth it IMO).

Each of these bits build on the other and when put together make an environment that simulate a modern web production hosting platform.

VirtualBox

First up is to download VirtualBox which is the virtual machine.
VirtualBox

 

Vagrant

Next download and install Vagrant

Vagrant

 

Vagrant Plugins

I recommend installing 2 Vagrant plugins one is for host mapping, the other backs up the WordPress databases when Vagrant is halted – do this in the Terminal, just cd to your home directory and run.

vagrant plugin install vagrant-hostsupdater
vagrant plugin install vagrant-triggers

Installing the VVV, VVV Variable and VVV Dashboard

Next is to install VVV which is the script that installs the 4 WordPress versions. The latest stable version, the latest trunk version and two other versions containing source and build files.

For VVV, VVV Variable and VVV Dashboard I recommend installing them with Git but you can also download the zips and move everything in place.

You can also install VVV Variable via HomeBrew which will also fix up the path issue mentioned later.

VVV (Varying Vagrant Vagrants)

git clone https://github.com/Varying-Vagrant-Vagrants/VVV.git localdev

So cloning the VVV repo above I am creating a directory to store it called localdev, if you don’t pass in a name it will create and store the files in a directory named VVV which is fine too.

vvv

 

 VVV Variable

git clone https://github.com/bradp/vv.git

This will add the Variable VVV files in a directory named vv

Variable VVV

 

VVV Dashboard

Move into your VVV installation root directory

git clone https://github.com/topdown/VVV-Dashboard.git dashboard

Move the whole dashboard directory into VVV/www/default/

And from the dashboard directory copy/move  the dashboard-custom.php file to the folder above –  VVV/www/default/

 

vvv-dashboard

First Time Boot Up

So that’s all the software installed, now in Terminal, change directory to your development directory either localdev, VVV of other one you set and run…

vagrant up

Time for a break whilst the vagrant box is built and software installed and configured which is known as provisioning. When it is all finished you will be able to login and view the 4 default sites that VVV creates.

Default VVV Sites

When it is finished Go to http://vvv.dev and see the 4 default VVV WordPress sites – these 4 versions of WordPress are updated each time the provision script is run – you can force it by running

vagrant provision

The WP-Admin logins to these sites and also ones created with the vv command are admin/password.

vvv-dashboard-home

You can also access phpMyAdmin via the Built In VVV Tools and the phpMyAdmin login is root/root

Currently with VVV Dashboard there are some issues with VVV2 in that it doesn’t display sites provisioned natively.

Native Provisioning or Variable VVV

Native provisioning for additional sites is done via the vvv-custom.yml file which doesn’t exist in a VVV fresh install, what you do is copy the existing vvv-config.yml and rename it vvv-custom.yml – that way your modifications are preserved when VVV is updated.

Once the custom file is made create a new site called test.dev you could add under the sites section…

 
test:
 repo: https://github.com/Varying-Vagrant-Vagrants/custom-site-template
 hosts:
   - test.dev

This is creating a site but with a custom WordPress site repo link provided by VVV, you can add your own repo.

When you have made changes do a provision for them to take affect…

Single Site Provision in VVV2 – quick

vagrant provision --provision-with=site-<sitenamehere>

Or All Sites Provision in VVV2

vagrant reload --provision

Now you will have a working new WordPress site at test.dev

Create new sites using Variable VVV

Provisioning with Variable VVV is not quite compatible with VVV2 but there is a workaround which makes it happen. Basically you need to add in the vvv-custom.yml file the name of the site before you use Variable VVV and format should be like so under sites:

 test:
 hosts:
 - test.dev

Then run Variable VVV from the command line

vv create

vv-create

Follow the wizard, and when ready see the new site listed in http://vvv.dev or visit the site directly.

Using BluePrints with VVV Variable

You can set up blueprints with vv by running:

vv --blueprint-init

This will create a sample json file in the root directory of your development called vv-blueprints.json, use this as a starter and append multiple ones in the same file, give each a unique name and follow the json formatting. Use call the blueprint when going through the vv create wizard.

Halting and Destroying the Vagrant Box

To halt the vagrant box run

vagrant halt

To run it up again run

vagrant up

To delete the box run

vagrant destroy

To ssh into the box

vagrant ssh

By running vagrant destroy your WordPress files are still intact in your development/www folder and if you have the vagrant triggers plugin installed the databases are backed up in database/backups.

Resources

New VVV2

Mentioned In Article

More

8 Comments

  1. Alex on August 3, 2016 at 9:49 pm

    Thanks a lot for very helpful article!

  2. Jeff Behnke on May 25, 2016 at 12:20 am

    Hello Neil,
    My name is Jeff, topdown on Github. I am the creator of VVV Dashboard and just wanted to say thanks for including it in your post.
    Keep an eye on it as when ever I get some free time, I usually put some time in on VVV Dashboard.

    I just released a new version today 0.1.7 that includes more features.

    Again, thanks for the mention.

    • Neil Gowran on May 25, 2016 at 11:11 pm

      No worries Jeff, I think you are doing a great job with it.

  3. Mohamed Abd Elhalim on September 16, 2015 at 7:39 am

    Thanks man for Custom Provisioning file, it’s working like charm ! it’s take from 40 to 60 seconds, but do this affect on the creating site process ? i mean the new site will be the same like default file process ?
    and thanks for post.
    regards

    • Neil Gee on September 19, 2015 at 3:15 am

      Yes will be the same as when using full provision – but you should still do full provision to keep everything else up to date – so maybe run once a week or fortnight

  4. Ian Douglas on August 22, 2015 at 7:28 pm

    A quick follow up on my last comment: I dropped your script into the provision folder on my dev folder and then ran vvv create. It halts Vagrant and then does its work, but I saw no difference in the time it took to go through the process. It was still trying to update a lot of components, and it still ran through all my other domains on that dev folder, updating WordPress on all of them. The process is still running as I type, at around 15 minutes so far. Mind you, I’m on a Third World ADSL connection.

    • Neil Gee on August 22, 2015 at 9:57 pm

      Make sure the custom script is named correctly and is executable – provision time should be between 1-2mins Vagrant Provision

  5. Ian Douglas on August 22, 2015 at 6:55 pm

    Thanks for this run down. Am I right to think that vagrant –provision would force a full provision, thus overriding the custom provisioning of your amended script? I know ideally I’d have a separate VM for each new domain/site I’m building locally, but I kinda fell into the practice of using one VM, running Vagrant, to store multiple domains/sites. Adding a new site is a long process, though easy and automated (thanks to VVV Site Wizard … ). I’d love to force the process to just do what is necessary to get one new site up and running. I’m guessing that that is what your custom script will do. Then every once in a while, as you suggest, I can run the full provision when I don’t need to be at the computer, to keep things updated. On another point, I didn’t try Variable VVV. I have VVV Site Wizard installed. They’re separate commands (vv as opposed to vvv), but is there any chance of a conflict in installing Variable VVV, to try it out? I’m very happy with VVV Site Wizard. It gives a prompt for the basic info I need to enter and then executes the build. Maybe there’s something I’m missing, or it is missing? Would be happy to read any comments on this you have.

Leave a Comment





%d bloggers like this: