it's hard to mess up "vagrant up"
Say goodbye to XAMP, WAMP and all the other WAMP stack all-in-ones. Seriously, uninstall them. There’s a new kid on the block and his name is Vagrant. Coupled with virtualization software such as VirtualBox and VMWare, Vagrant allows you as a developer to create portable development environments in a matter of seconds.
You’re a smart person though, and you can research how to set up Vagrants and all of the amazing features they offer. With this article, I’m going to cut to the chase on how to get your development environment up and running as quickly as possible in Windows, skipping over a lot information regarding Vagrant.
In order to get this going, a few programs will need to be installed. First and foremost, you’ll need to install Vagrant.
Second, because linux CLI is so amazing, Cygwin is a must. That, and because Cygwin allows you to install other very useful packages during install. The packages that will prove useful (and you can search for them with the handy search field in the installer) are ssh, git, svn, and an editor of your choice. I like nano. You can always rerun the installer to add other packages.
For those unfamiliar with Cygwin, just think of it as a handy terminal for Windows. Once installed and opened, it will place you in the home folder of the Cygwin. The actual windows file system is accessible via the root folder
/cygdrive. I’ve been saving my different Vagrants inside a
~/vagrant folder in my Cygwin home folder for quick access. You can make one too by running
mkdir vagrant inside your home folder. Additionally, for your first Vagrant, create a
test-dev folder inside the
And third, install VirtualBox. VirtualBox is the default virtualization tool used by Vagrant.
Once Vagrant, Cygwin+packages, and VirtualBox are installed, you’re ready to get a VM set up with a few simple commands.
Like I said before, I won’t be going into much detail regarding Vagrant configuration files and functionality. Instead, we’re going to use an amazing website called PuPHPet.com. What PuPHPet does is allow you to easily create your Vagrant configuration file via a slick UI. For simplicity’s sake, I recommend your first Vagrant use all of the default settings on PuPHPet except for one. Change the distro to Ubuntu 12, because that’s what I’m used to and we can have the same settings. If you change anything else, I can’t guarantee you’ll be able to walk through the rest of this article.
Once you’ve changed the distro, jump down to the create section and download the configurations. PuPHPet will give you a zip with a folder inside named with a bunch of random characters. Inside that folder is the configuration files you need. Copy those files into the
~/vagrant/test-dev folder created earlier in Cygwin. Using Window’s file explorer, that folder is located at
Now, in Cygwin, navigate to the
~/vagrant/test-dev folder and run the command that makes Vagrant so amazing:
When that’s done, realize you have just created a fully functioning LAMP stack, and in addition to everything being set up and turned on, the contents of your
~/vagrant/test-dev folder are now accessible to the VM via VirtualBox’s shared folders and symlinked to its apache web root in
/var/www. You should now be able to navigate to http://192.168.56.101/ in your browser. Before you go there though, add phpinfo to an index.php in your
~/vagrant/test-dev/default to double-check php is installed.
Woohoo, PHP is installed!
A MySQL server was also created and can be accessed via your windows MySQL client through SSH tunneling. In order to do this, you'll need to use the key generated by PuPHPet. My MySQL client of choice is SQLyog which has SSH Tunneling available via the SSH tab. Use the following information in your MySQL client on your host machine to connect to the vagrant's MySQL server:
- host address: localhost
- username: dbuser
- password: 123
- ssh host address: 192.168.56.101
- username: vagrant
- passphrase: vagrant
- public key:
And there you go, you should be able to connect to your Vagrant’s MySQL server. Other Windows MySQL GUIs should have very similar options for creating connections. You can use that same key to SSH into the VM via putty, or you can simply run
vagrant ssh via Cygwin anywhere inside your Vagrant folder to SSH into the machine.
The configuration files copied from PuPHPet are the DNA of this Vagrant. You can run
vagrant up on any machine with Vagrant installed with those configuration files, and it will create the EXACT same development environment that you just created. No longer is creating development environments a tedious task with a million hiccups along the way due to differences in OS or simple user error. It’s really hard to mess up
But, I’m tired of this VM, and I want the space allocated for the VM back. So, in Cygwin, run
vagrant destroy. The VM you just created no longer exists. All that’s left are the config files and the web root folders such as
~/vagrant/test-dev/default. There’s no need in keeping the VM lingering about when you're not developing anymore, but there are ways to keep the VM and shut it down,
vagrant halt, or suspend its current state,
vagrant suspend. To get the VM back up and running, no matter the case, just run
This was a crash course on getting a Vagrant up and running fast, and I hope you’re already in the process of uninstalling XAMP or whatever other WAMP stack you were using before. Those Windows stacks were useful at one point in time, but they really can’t beat Vagrant. If you’re new to Vagrant, definitely read up on more of its configurations and functionality. PuPHPet really does all of the work for a quick VM, but Vagrant also offers a lot of other functionality. For instance, VagrantCloud allows for you to instantaneously share your Vagrant VM to the outside world with a single command
vagrant share. Okay, time to get back to work:
image credit: http://www.vagrantup.com