Configuring a Magento development environment with Ubuntu and Vagrant

magento_vagrant

Starting a new Magento project (or any framework backed project) can involve tedious tasks before you even begin coding. Download the latest Magento version, extract, configure a database, update the application config etc… It can take quite a while to get going.

What if you could run a few simple commands to automate the above steps?

What if you could automatically configure a development environment using a virtual machine to closely emulate a production environment?

With Vagrant, both of the above are possible (and a whole lot more).

What is Vagrant?

In very simple terms, Vagrant works alongside Virtualbox to allow simple provisioning of a virtualised server, tailored specifically to your project. In fact, Vagrant provisioner configuration scripts used to build your development machine can be committed with to your project’s repo. This allows other developers to get to work on your project using an identical and predictable dev box to test their code.

For me, Vagrant’s killer feature is the fact that the configuration of each box is completely autonomous. This allows you to tailor a development box to your exact requirements for a single project, without affecting any other projects or your local machine. In contrast, installing a web server directly on your local machine would usually require global configuration options, modules and messing with ports and local DNS configuration. Vagrant boxes and provisioners are clean, non-destructive and easily removed leaving your development machine just as it was before.

A Simple Magento Development Environment

To get started, I have put together a simple shell script provisioner for getting a Magento installation running on a Ubuntu virtual box. This automates the following steps:

  1. Download a bare Ubuntu “Box” (Precise 64bit 12.04)
  2. Install PHP 5.3, MySQL 5.5, Apache 2.2
  3. Configure an Apache virtualhost file and web directory
  4. Create a database and database user for Magento
  5. Download Magento (CE 1.7.0.2) from the official site
  6. Extract Magento into the web root directory and set appropriate folder permissions
  7. Run Magento’s PHP/command line install script
  8. Bridge the virtual machine’s network to allow access from host machine (i.e. your web browser)

Check out my provisioner project on Github. It’s deliberately very simple and unopinionated, leaving plenty of scope for you to tailor the configuration to your specific requirements. It’s perfect for getting from naught-to-magento in a couple of minutes allowing you to get coding as soon as possible.

Advertisements

2 thoughts on “Configuring a Magento development environment with Ubuntu and Vagrant

  1. This is fantastic and works like a charm! My client is running Enterprise Edition. What is the approach to upgrade from 1.8 to 1.13 via vagrant?

  2. Thanks 🙂 I’ve not tried this, but if you have a copy of EE, you can either “vagrant ssh” in and install yourself. Alternatively, you could update the bash script to point to a copy of EE in the shared /vagrant directory, rather than downloading CE from Magento.com. Run “vagrant reload” and it will re-provision the virtual machine.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s