Book Image

Magento PHP Developer's Guide

By : Allan MacGregor
Book Image

Magento PHP Developer's Guide

By: Allan MacGregor

Overview of this book

<p>Magento has completely reshaped the face of e-commerce since its launch in 2008. Its revolutionary focus on object oriented and EAV design patterns has allowed it to become the preferred tool for developers and retailers alike.</p> <p>"Magento PHP Developer’s Guide" is a complete reference to Magento, allowing developers to understand its fundamental concepts, and get them developing and testing Magento code.</p> <p>The book starts by building the reader’s knowledge of Magento, providing them with the information, techniques, and tools that they require to start their first Magento development.</p> <p>After building this knowledge, the book will then look at more advanced topics: how to test your code, how to extend the frontend and backend, and deploying and distributing custom modules.</p> <p>"Magento PHP Developer’s Guide" will help you navigate your way around your first Magento developments, helping you to avoid all of the most common headaches new developers face when first getting started.</p>
Table of Contents (16 chapters)
Magento PHP Developer's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Up and running with Vagrant


Previously, we created a Magento install 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 without experience working on 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 by using Vagrant in combination with Chef. We can create automated VMs without the need of having an extensive knowledge about Linux or the different LAMP components.

Note

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

Installing Vagrant

Vagrant can be downloaded directly from downloads.vagrantup.com. Furthermore, its packages and installers are available for multiple platforms. Once you download Vagrant, run the installation.

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 http://files.vagrantup.com/lucid32.box
$ 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 as 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 who start working with Magento, I have created a Vagrant repository on 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.

If you are using Ubuntu, run the following command:

$ sudo apt-get install git-core -y

For Windows, we can use the native tool at http://windows.github.com/ 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/magento-vagrant/ to download and save our repository; inside magento-vagrant 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 Vagrant box.

The only thing now left to do is to set up our development sites. The process of adding 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 Vagrant box; 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, which can be found at the location C:/Users/magedev/Documents/magento-vagrant/data_bags/sites/default.json:

{
    "id": "default",
    "host": "magento.localhost.com",
    "repo": [
        "url": "svn.magentocommerce.com/source/branches/1.7",
        "revision": "HEAD"  
     ],
   "database": [
      "name": "magento_staging",
      "username": "magento",
      "password": "magento2013$"
   ]
}

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

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

Now that we have a running Magento installation, let's look into choosing a proper integrated development environment (IDE).