A WordPress Meetup Introduction to Vagrant – What You’ll Need

Note: I’ll be giving a couple of talks about getting started with Vagrant over the next couple months and I intend for this to be a decent description covering some of the basics those who are attending should complete. If are planning on attending in PDX or Seattle, please read this through and complete the steps as best you can.

I wrote an initial blog post a couple months ago that highlights my fascination with Vagrant and may help give a broad overview of the problem I was trying to solve. Keep in mind that I went from eager excitement to mind blown user of Vagrant within 24 hours. This will be you.

Download the matching VirtualBox Extension Pack (4.2.6), the same for all platforms, and install it on your computer. Having VirtualBox installed should make this a recognized file type. https://www.virtualbox.org/wiki/Downloads

Vagrant

Vagrant is an open source (MIT) tool that allows you to setup one or multiple development environments on your local machine that are sandboxed away from your operating system. The getting started guid describes it best:

Read the overview page of the getting started documentation for Vagrant. If it doesn’t make sense, don’t worry. A familiarity with the terminology will be helpful. Bonus points for every page past the overview section you read. It will all be helpful the second time around. http://docs.vagrantup.com/v1/docs/getting-started/index.html

Create a project.

Vagrant is best explained when you are already up and running with it. To best be prepared for the meetup, it would be great if everyone had the following completed.

Somewhere on your computer, decide where you want a local environment to live and navigate to that directory. For sanity, I’m going to use ‘pdxwp-vagrant‘ as the environment directory and ‘development‘ as the directory it will live in on your computer.

Navigate to the containing directory via ‘cd development‘

Clone the varying vagrant vagrants repository with ‘git clone https://github.com/10up/varying-vagrant-vagrants pdxwp-vagrant`. This will create a directory called ‘pdxwp-vagrant‘ in your ‘development‘ directory that contains all of the files we will need to start up vagrant.

If you don’t have git available to you by the command line, you can extract the repository’s zip file into a ‘pdxwp-vagrant‘ directory instead.

Change into the ‘pdxwp-vagrant‘ directory and type ‘vagrant up‘

A series of messages will appear indicating that Vagrant is downloading a ~600MB box that will act as the base of the virtual machine that we are building. This box started with a specially packed version of Ubuntu 12.0.4 made available directly from Vagrant’s servers. I then installed nginx, mysql, php-fpm and memcached before repackaging it for distribution. This allows us to skip a lot of the provisioning.

Boxes are cached in your user’s home directory under ‘~/.vagrant.d/boxes`. As long as nothing changes with the ‘config.vm.box‘ or ‘config.vm.box_url‘ parameters in your ‘Vagrantfile‘, the box should stay cached on your system until it is deleted so that you do not have to download 600MB every time you start the server.

Once ‘vagrant up‘ has finished, you’re ready to go. By default the IP address of the box is ‘192.168.50.4‘. Add an entry for this IP address to your hosts file that points to ‘local.wordpress.dev‘. This will give you access to a default WordPress install right off the bat.

And you’re ready! At this point, don’t worry about screwing anything up. As long as you have VirtualBox and Vagrant installed and the 600MB box cached to your machine, interacting with the box during the meetup will be a breeze.

I’m looking forward to your presentation. I’ve been wanting to try Vagrant for a while now and here’s my chance.

Question: I installed the precise32.box as per your directions. I’m familiar with this version of Ubuntu since it’s the same as what I’m running on my file server. Out of curiosity I SSHed into into it and (as sudo) ran apt-get update. There were a whole slew of upates available so I went ahead and did the update. I don’t know what the security risks are running in a VM, but I figured I’d better be safe than sorry. Now on to my question, is my having done this going to interfere with my ability to follow along with your presentation? If the underlying OS is out of sync with what you’re using, will that change anything on the Vagrant side of things?

This is actually fantastic. I can’t see it causing any issues at all and is a great first step when dealing with a new box. In fact, I should probably make that part of the default provisioning.

I would say keep playing around with it until Monday and it will fit in with the presentation and discussion just fine. And if something breaks, a quick vagrant destroy and vagrant up will have you back to the base in minutes.

Thank you, it seemed to work for me. One glitch–I read the Vagrant instructions as you said, but (without thinking) followed their initial install instructions on the first page. Then–I switched back to your instructions. Mayhem ensued. So, I deleted the first box, then followed *only your install instructions*. No mayhem.