Having continuous integration (or CI) in your development cycle is almost like a silver bullet. It can not only help boosting your code quality but also increase your productivity significantly. Recently I have been working on some PHP projects and I came to the conclusion that I needed my own CI environment to improve my QA.
Having worked on Java projects for quite a while I am quite familiar with Jenkins (formerly known as Hudson). Luckily there are some easy to follow tutorials on how to set up Jenkins so it fits into a PHP workflow. I used Jenkins-PHP and it was really helpful.

Make things easy

However, as I know a lot of folks working on PHP projects, but only a fraction of them actually use CI. I assume one of the reasons is that a full CI server might be a bit intimidating to set up. Even following the instructions from jenkins-php.org required some intense debugging to get things right.

Naturally I thought of a way to automate setting up Jenkins for PHP, as I am always looking for ways to keep my home lab as flexible as possible. Part of it is being able to easily migrate between servers within the shortest time possible. Rather than giving you a detailed walkthrough of all the steps required to set up Jenkins for PHP (which, by the way, are already extremely well documented in various tutorials around the web) I decided to seize the opportunity and create this: An automated set up of Jenkins with the PHP templates using Ansible.

It is really simple to use, let me show you in less than 7 minutes:

Grab the code

Basically there are two repositories on my github

  1. php-ci – a bootstrap solution for your own Jenkins server
  2. sample-yii-project – a project to demonstrate CI with PHP using the Yii framework

To bootstrap the server you really only need to set up a Debian box and perform two (yes, 2) lines of code. That sets up your entire CI system. If you have never used CI before or you tried and stopped using it because it took so long to set up, set up your own box now – I promise you will wonder how you ever lived without CI before.

The magical commands are:

your-debian-machine root$ wget https://raw.github.com/yauh/php-ci/master/install.sh
$ /bin/bash install.sh

If you have any problems, you can create issues on github. If you want to help improve the solution feel free to fork and create a pull request. Also you could create (or point me to existing) PHP projects that demonstrate how to use different frameworks in the CI context.

Enjoy using Continuous Integration, I am off now working on improving my PHP code quality.