Technology

An Introduction to Vagrant

Posted by Pixafy Team

You may or may not have heard of it or know what it does, but Vagrant is a fantastic tool for building complete development environments, and is something we’ve recently been using at Pixafy. From standardizing our development environments to making the process of setting up new projects a breeze, Vagrant has already helped solve a lot of our day-to-day problems, and we’re excited to develop new features for it and continue to enhance its capabilities.

Problems that need solving

Before we dive into Vagrant and how to get started, it’s worth noting some of the common problems one commonly faces when inheriting a project of any kind.

Setting up is a hassle This isn’t always a guaranteed problem. There are some sites that organize things in a sane manner and have everything ready to go. Then there’s that one project that takes ten engineers to tell you how to configure the site and import the database, (you know, the one that will only run on your laptop because you don’t want to go through the torture of setting it up again). We needed a way to standardize and hopefully automate an entire development environment from start to finish with no assistance necessary.

Developing is done on multiple OS – If you’ve ever fallen victim to this “bug” in your code, then you know how frustrating working on Windows can sometimes be. Since the Windows filesystem is case-insensitive, “Block/MyFile.php” and “Block/Myfile.php” are interpreted as the same file. As a direct result of this, classes like “Pixafy_Example_Block_MyFile” could also be written as “Pixafy_Example_Block_Myfile”. All four of the mentioned combinations would work on a Windows environment, which is not good when the rest of our architecture is strictly Linux. We needed to set up developers on environments that best mimicked those of our production and staging environments.

Automation is hard – Running crons on a local machine can get a bit crazy when you start to have a large amount of projects. Deploying to different websites can also get hectic when you need to remember the guidelines on how each site make its way to the production server. Our solution needed a way to separate out these processes based on the project and make them easy to use and understand.

When looking at the common problems, it’s pretty easy to decide that we were looking at some sort of Virtual Machine solution.

Getting Vagrant Set Up

Simply put, Vagrant is a virtual machine that you can expand to do almost anything with. For web developers, it allows us to essentially replace our WAMP/XAMPP/MAMP projects with an individual working copy of a project, specially designed to meet all the site’s intricate requirements.

Let’s get setup. To start, you need to install the application below (for any assistance, consult the documentation for either program):

VirtualBoxDownload
VagrantDownload

After installing each program, you are now ready to get your first project underway. I’ve create a demo project that you can download here.

Simply clone or download the repository. Navigate to the project folder in terminal or command prompt type “vagrant up”. The project should now be “provisioning” or setting up. In the matter of minutes you should have a full working Magento environment ready to go.

Neat, right? You can see how easy it is to now work with a team of developers (even on a global level) and still be confident that everyone’s environment is going to behave precisely the same as yours.

If you want to have some fun with Vagrant, try creating a new module for the Magento demo and submitting it back to Github. If the code is solid, we’ll merge it into the master branch for future readers to download.

Conclusion

With all that’s been said, there is still a lot to Vagrant we have yet to dive into. This article should serve only as a general overview of what Vagrant is, what problems it can help solve, and how we currently use it here at Pixafy. Overall, it is an extremely powerful piece of software that takes some fine-tuning before getting just right, and we hope to cover more advanced topics in the future.

Cheers!

About Pixafy

Pixafy develops eCommerce technology products for clients and end users which leverage open source solutions such as Magento. Established in 2010, the award-winning company is responsible for building a portfolio of eCommerce products that generate over $125 million in annual revenue. Pixafy’s mission is to help champion the open source movement by introducing user inspired products that replace time and cost intensive development with automated technologies.