Book Image

Magento PHP Developer????s Guide, 2nd Edition

By : Allan MacGregor
Book Image

Magento PHP Developer????s Guide, 2nd Edition

By: Allan MacGregor

Overview of this book

Table of Contents (16 chapters)
Magento PHP Developer's Guide Second Edition
About the Author
About the Reviewers

Up and running with Vagrant

Previously, we created a Magento installation wizard using a VM. Although using a VM gives us a reliable environment, setting our LAMP for each of our Magento staging installations can still be very complicated. This is especially true for developers who don't have experience working in a Unix/Linux environment.

What if we could get all the benefits of running a VM but with a completely automated setup process? What if we were able to have new VM instances created and configured on the fly for each of our staging websites?

This is possible using Vagrant in combination with Chef. We can create an automated VM without the need for extensive knowledge of Linux or the different LAMP components.


Currently, Vagrant supports VirtualBox 4.0.x, 4.1.x, and 4.2.x.

Installing Vagrant

Vagrant can be downloaded directly from Furthermore, its packages and installers are available for multiple platforms. Once you have downloaded Vagrant, run the installation file.

Once we have installed both Vagrant and VirtualBox, starting a base VM is as simple as typing the following lines in the terminal or Command Prompt depending on the OS you use:

$ vagrant box add lucid32
$ vagrant init lucid32
$ vagrant up

These commands will start a new Vagrant box with Ubuntu Linux installed. From this point onward, we could start installing our LAMP server as per normal. But why should we spend an hour to configure and set up a LAMP server for each project when we can use Chef to automatically do it? Chef is a configuration management tool written in Ruby that integrates into Vagrant.

To make it easier for developers to start working with Magento, I have created a Vagrant repository in GitHub called magento-vagrant that includes all the necessary cookbooks and recipes for Chef. The magento-vagrant repository also includes a new cookbook that will take care of the specific Magento setup and configuration.

In order to start working with magento-vagrant, you will need a working copy of Git.

In Ubuntu, run this command:

$ sudo apt-get install git-core -y

In Windows, we can use the native tool found at to download and manage our repositories.

Regardless of the operating system that you are using, we will need to check out a copy of this repository into our local filesystem. We will use C:/Users/magedev/Documents/mage-vagrant/ to download our repository. Inside the mage-vagrant folder, we will find the following files and directories:

  • cookbooks

  • data_bags

  • Public

  • .vagrant

  • Vagrantfile

The magento-vagrant repository includes cookbooks for each of the components of our development environment, which will be installed automatically as soon as we start our new VagrantBox.

The only thing left to do now is to set up our development sites. The process to add new Magento sites to our vagrant installation has been simplified through the use of Vagrant and Chef.

Inside the data_bags directory, we have one file for each Magento installation inside our VagrantBox; the default repository comes with an example installation of Magento CE 1.7.

For each site, we will need to create a new JSON file containing all the settings that Chef will need. Let's take a look at the magento-vagrant default file.

The file location is C:/Users/magedev/Documents/mage-vagrant/data_bags/sites/default.json. Here are the contents of the file:

    "id": "default",
    "host": "",
    "repo": [
        "url": "",
        "revision": "HEAD"   
   "database": [
       "name": "magento_staging",
       "username": "magento",
       "passwod": "magento2015$"

This will automatically set up a Magento installation using the latest files from the Magento repository.

Adding new sites to our VagrantBox is just matter of adding a new JSON file to the corresponding site and restarting the VagrantBox.

Now that we have a running Magento installation, let's look into choosing a proper Integrated Development Environment (IDE).