Today I wanted to try out the StackPHP project to see how it could benefit me at work or in my side projects. However, I faced a roadblock: I only had access to PHP 5.3.8, and several of the StackPHP examples require PHP 5.4! What was I to do?
As it turns out, I already knew the answer, but I'd never tried it. A fellow developer, Juan Treminio, recently launched a project that can assist in this sort of scenario: PuPHPet, the online tool for generating vagrant+puppet virtual machine configurations.
So, while preparing a BBQ dinner, I decided to give it a go.
What are Vagrant and Puppet?
Vagrant helps automate the creation and destruction of virtual machines. Combined with a virtual machine platform like VirtualBox, it can be used to start and stop environments on a whim. It also gives you the ability to commit the "Development" or "Staging" environment to your version control system, allowing all of your developers to share the exact same configuration while working on your codebase.
Puppet is a configuration management tool. It can be used to do all kinds of crazy things with servers and workstations. It's especially useful in Enterprise environments and cloud-computing platforms: if you want to have hundreds of servers that all behave the same way, and if you want to be able to quickly deploy changes to all of them nearly instantly, Puppet can make that possible.
How Does PuPHPet Help?
PuPHPet provides an interface for choosing the type of virtual machine & configuring the initial state of the Operating System so you can get to work as quickly as possible. Doing this by hand can be a complicated process, so having the ability to generate exactly the template you want is a great timesaver.
First, head to the website and begin filling out the settings. Here's what I used (I'll leave out the items I stuck with the defaults for):
- Operating System: Ubuntu Precise 64 Bit (12.04.2 LTS)
- Sharing Your Folders: NFS
- I left this as the defaults just to see; this is where you'd choose custom packages to install
- Server name: stack.dev
- Server aliases: www.stack.dev
- Timezone: America/Vancouver
- MySQL Root Password: toor
- Database 1
- User: tester
- Password: testytesty
- Database Name: test_db
Next, I clicked "Create My Manifest" and decided to give it a try. PuPHPet sent a .ZIP file to my web browser containing the configuration.
After unzipping it to "
~/vagrant/stack.dev/", I took a look around:
- ... this folder contains all the reusable Ruby/Puppet code that configures the virtual machine
- default.pp (This file contains all of the custom settings specified in the above step)
I then ran "
vagrant up" ... which promptly failed. After looking into it, I realized that this is because I had Vagrant version 1.0.5 installed - PuPHPet configurations require version 1.1 or higher! A quick trip to downloads.vagrantup.com helped rectify this. Installation was quick and painless, and soon I had version 1.2.2 ready to go. I already had VirtualBox installed.
vagrant up, like a boss
After the box (virtual machine image) downloaded, Vagrant began the configuration process. It asked for an admin password so it could modify
/etc/exports in order to enable NFS - however, the mount failed, unfortunately. In order to investigate this, I ran "
vagrant ssh" and was surprised to immediately be inside the virtual machine! I had expected the VirtualBox interface and dock icon to appear during the boot process, but vagrant enabled a special Headless mode that is better-suited to server environments. I wasn't sure why the NFS mounts failed, but it certainly seemed like the rest of the process had worked.
At this point, I took a break to shuck some corn and skewer some peanut chicken satay for the grill. This step is optional, for those of you reading at home.
While the chicken was sizzling, I had a few seconds to look into things a bit more, and I realized that although SSH was running, Apache was not installed - this told me that the Puppet portion of the process had not actually executed.
I ran "
vagrant destroy" to shut down and erase the broken Virtual Machine, and then "
vagrant up" again to see how it would go.
This time, things worked much more nicely! It was a bit slow to run the Puppet processes, but that's understandable given how much downloading and installation had to be done. All told, everything was up and running within fifteen minutes. Even the NFS shares appeared to be fully functional - I could write to the local ("host") folder and immediately see the result inside the client.
Let's Get Dangerous
The next trick was finding out how to get the web server to respond to browser requests. After consulting the PuPHPet Help Page, I saw that I needed to add the IP address to my
/etc/hosts file (C:\Windows\system32\drivers\etc\hosts in Windows):
192.168.56.101 stack.dev www.stack.dev
Once this was done, everything worked fine - I was able to load
http://www.stack.dev/ in my web browser.
So that's how you set up your own personal VM using Vagrant, Puppet, and PuPHPet.
For more tips and updates on the projects I've been working on, please subscribe to the Whateverthing newsletter.
Thanks for checking in! I'm off to eat delicious grilled chicken and corn.
Pro Tip: Shuck the corn & run it under some water, put it on a sheet of tinfoil, add olive oil and salt, seal the tinfoil, and grill that for about 40 minutes to get some delicious corn on the cob!
- Excerpts, Summaries, and Breakpoints in Sculpin
- Sunsetting the Gibson Index
- Late Night Links
- Don't Forget the Catfood
- Late Night Links, Volume 4