I often brag about the fact that I've dumped heavy tools like XAMPP in favor of Vagrant.  I'm quite proud of this accomplishment, and I urge every other developer I meet to look into Vagrant.

Unfortunately, setting up Vagrant proves to be a bit trickier on Windows.  I admit, I struggled a bit with it myself when I first set things up.

A few days ago, though, I decided to swap out my aging Windows machine for a new one - so I have the opportunity to set up Vagrant again, from scratch, on Windows.

Let me walk you through it.

Prerequisites

I set up a handful of things on every Windows development box I used.  For the purposes of Vagrant, though, there are two tools in particular you'll want handy.

First, download and install Git.  You'll want to download the real command-line tool itself, not a custom GUI.  When you install, you have the option to add Git and its Linux-style command line tools to your system Path.  Do this!

If you already have Git installed, or you forgot to select this option upon installation, you'll need to add Git's [cci]/bin[/cci] directory to your Path manually.  I've already written instructions for how to do just that.

Screenshot 2014-03-04 17.21.50Second, you'll want to set up an elevated command prompt shortcut - this isn't a prerequisite for installing Vagrant, just a handy tool to have around.

I usually set up a custom shortcut in [cci]C:/Tools[/cci] that launches an elevated command prompt.  I also configure it to use [cci]CMD + ALT + HOME[/cci] as a shortcut key so I can launch a new elevated prompt whenever I need one.

Installation

The installation process is fairly straight-forward from this point: you'll have to download and install 2 things:

  1. VirtualBox (4.3.8 at the time of this writing)
  2. Vagrant (1.4.3 at the time of this writing)

There's nothing fancy to it, just install both and then move on with the process.

Configuring Your Environment

I use Varying Vagrant Vagrants (VVV) as a project template for my local environment.  If you're using the same this will help - if not, skip to the next section.

Use Git to clone VVV to wherever you want your projects to live on your hard drive (I keep mine in [cci]C:\Projects[/cci]).  If you have existing projects to pull in to the environment, you can drop them in custom subdirectories of [cci]/vvv/www[/cci] and configure the Nginx rules for the sites.  I'll leave that exercise for later.[ref]If you're stuck, look at the default sites and configuration that ships with VVV and build your custom site configs off that.[/ref]

The next step is to turn things on.  Launch your elevated command prompt[ref]An elevated prompt isn't strictly necessary here.  But I usually spin things up and then use the same prompt to run tools like Node and Grunt while developing.  Using a single prompt for all is just faster.[/ref] and run [cci]vagrant up[/cci].

Voila!  You have a local environment!

Working With Vagrant

The biggest reason we installed Git (and set it in our Path) in the beginning was to grant access to a *nix SSH tool.  You can now log in to your vagrant box with a simple [cci]vagrant ssh[/cci].  Without this tool, you'd need to download, install, and configure a tool like puTTY to access the system.

I like simplicity; [cci]vagrant ssh[/cci] from an existing prompt is easier.

You'll also likely want the ability to work with your MySql databases from something other than the command line.  Personally, I use MySql Workbench.[ref]It's conveniently free, open source, and built by the same people who build MySql in the first place.[/ref]  Once installed, it can connect to a database server over an SSH tunnel and run commands remotely.

Screenshot 2014-03-04 17.38.46

If you're using VVV, then your SSH username is "vagrant," your SSH keyfile is stored in [cci]C:\Users{your name}.vagrant.d\insecure_private_key[/cci], your MySql username is "root," and your MySql password is "root."  Set up all of the above and you'll have a solid connection to your database from something other than the command line.

What's Left?

Vagrant is just one tool I use to make local development easier on Windows.  Luckily for me, it also makes web development easy on Mac, too.

With the exception of the elevated command prompt above, all of the software I've listed in this article are cross-platform.  I use the exact same tools on my Mac that I use on my PC.

In addition to the above, I also have a standardized IDE, test suite, and command-line helper tools that make writing code easier, faster, and less error-prone.

What tools would you add to the above to help new developers get started, regardless of platform?