Intro to Vagrant with Kohana and Zen Kommerce

If you work in web development you most likely have suffered through the pains of building your dev environment on more than one occasion. The chances of having dependency problems grow with the size of your team making it difficult to be productive. This is especially true for open source projects when lowering the barrier to entry can net you more contributors. In this post I will walk you through our development environment for Zen Kommerce, an open source e-commerce platform, built in the PHP Kohana framework.

Prerequisite Software

VirtualBox was chosen as the virtualization platform on which our development environment resides. This provides a consistent foundation to install packages and maintain dependencies for efficiently managing code. Visit virtualbox.org to download the latest version.

We are using Vagrant to create a common and consistent workflow to get the most out of our contributors. Getting started with our project is as simple as typing “vagrant up”. Visit vagrantup.com to download the latest version.

Overview

Now that you have the required software installed, we can see how everything fits together. Below is an overview of the software we are using in Zen Kommerce version 0.1.0 which is simply an empty checkout of Kohana 3.3.1. You could even use this as a starting point for your own projects!

  • CentOS 6.4 (x86_64)
  • Percona Server 5.6 (MySQL)
  • PHP 5.5.9 w/ OPcache 7.0.3 & PHP-FPM
  • Kohana 3.3.1
  • Nginx 1.4.5
  • HAProxy 1.4.24
  • Redis 2.8.5
  • Sphinx 2.1.5
  • Gearman 1.1.12
  • Maxmind GeoLite2
  • Codeception 1.8.2
  • ImageMagick 6.5.4
  • Apache Fop 1.1

Getting Started

Fork the Zen Kommerce project, git clone your new fork into a directory on your local machine and type the command below. Note: The first time can take 20+ minutes to install and compile packages.

vagrant up

The behind the scenes installation magic happens in the Vagrant bootstrap file and the build scripts, but you don’t have to worry about that because you are using Vagrant!

Verify Tests

Now you can run the Codeception acceptance tests to verify your environment is up and running.

codecept run

Codeception Acceptance Test - Welcome

Excellent! The first test is a simple one that ensures Nginx, PHP, Kohana, and the homepage are working. Codeception is a PHP testing framework that drives our acceptance, functional, and unit tests. Acceptance tests are executed using the PhpBrowser module; basically sending Curl requests and interacting with the raw HTML to make assertions. These tests are executed very quickly emulating a non-javascript browser. In the future, the acceptance tests can be run through Selenium2 to simulate browser testing of the application in multiple client environments which is beyond the scope of this topic.

Summary

Now you have a working development environment with all the tools you would ever need to build a Kohana application. The Kohana PHP Framework provides features such as a Cascading Filesystem for modularity, a scalable HMVC design pattern, an elegant ORM, excellent routing, exception handling, and code profiling. For over ten years I have used LightVC, Zend Framework, CodeIgniter, CakePHP, and Laravel in production environments; and Kohana 3.x is my personal choice by leaps and bounds.

In future posts, we will dive deeper into Kohana and the Zen Kommerce project to see what is possible when using the right design patterns. We will explore external tools such as full-text faceted search with Sphinx, PDF generation with Apache FOP, image manipulation with ImageMagick, background worker queues with Gearman, restricting country IPs with Maxmind GeoLite2, and caching strategies with Redis. And we just might build a scalable e-commerce platform along the way!

Leave a Reply

Your email address will not be published. Required fields are marked *