The maturing Web development industry is inextricably intertwined with a constant companion: complexity. Gone are the days of assembling a few simple database-backed PHP-driven pages and calling it a website; these days clients expect rich JavaScript-based user interfaces, cloud-backed data stores, and tight integration with third-party APIs. To accommodate such challenges, developers have put a great deal of time and effort into devising tools and techniques which help to identify, track and resolve bugs. One such technique is continuous integration, which facilitates the merging of code changes made by various members of a development team by automating tedious processes such as testing, documentation generation, and deployment.

One popular continuous integration tool is Jenkins. (Jenkins is a recent fork of another continuous integration project named Hudson.) Although a Java-based solution, an active plugin community has made it possible to use Jenkins for far more than Java-specific projects. More recently it has become much easier for Jenkins' novices to use the project in conjunction with PHP projects thanks to the work of Sebastian Bergmann. Known as Template for Jenkins Jobs for PHP Projects, the project provides a configuration file which you'll use to enable Jenkins/PHP integration, and supports several popular familiar PHP tools such as PHP_CodeSniffer and PHPUnit. In this article I'll introduce you to just a few of the great ways you can begin using Jenkins in conjunction with your future PHP projects.

Installing Jenkins

Jenkins is supported on a wide variety of platforms, including Windows, Linux, and OS X. Head over to the official website to download the appropriate version. You'll also need to install a JDK if one isn't already installed. If you are using a Linux-based system then Jenkins is likely available via your package manager. For instance I used the following sequence of commands to install Jenkins on my Ubuntu laptop:

$ wget -q -O - | sudo apt-key add -
$ sudo su
$ echo "deb binary/" > /etc/apt/sources.list.d/jenkins.list
$ exit
$ sudo apt-get update
$ sudo apt-get install jenkins

Once installed Jenkins will automatically start and additionally be configured to automatically start as a service upon reboot. Next, head over to http://localhost:8080/ to begin the configuration process.

Next you'll need to configure Jenkins using Template for Jenkins Jobs for PHP Projects. This is actually a fairly involved process requiring you to install several PEAR packages and Jenkins plugins. Although Sebastian has done a thorough job documenting this process, there are a few missing details which will likely trip up those unfamiliar with the aforementioned PEAR packages. Therefore in addition to reviewing the instructions found at the project website, I also suggest reading Volker Dusch's excellent writeup.

Configuring Git Version Control System with PHP

If you're using Git for source control, you'll want to install Jenkins' Git plugin. The aforementioned documentation explains how to install Jenkins plugins. If you are using Git, one common source of confusion involves defining the project repository location. You have the option of identifying the location using URLs or local paths. When using the latter, you need to prefix the path with file://, for instance file:///

After restarting Jenkins, define Jenkins' Git username and email address by entering Jenkins' Web interface and navigating to Manage Jenkins > Configure System and setting these values under the Git plugin section. Performing this last step is important because neglecting to do so will cause your builds to fail due to Jenkins' inability to access the project log and tag the project due to Git complaining about the lack of a proper username.

Exploring Jenkins Continuous Integration with PHP

With your project defined, it's time to begin exploring Jenkins' capabilities. After the project has been defined you'll be returned to the project's Jenkins home page. This home page includes a menu (see Figure 1) which you can use to perform various tasks, including building the project on-demand (you can automate the build process in various ways; the configuration page offers three such options), performing configuration changes, and notably, viewing build information.

Template for Jenkins Jobs for PHP Projects
Click here for larger image

Figure 1. Jenkins' Project Menu

Try building your project by clicking the Build Now link, and after a moment you'll see an entry appear in the project build log which is located directly below the menu. Click the entry link and you'll be presented with some useful information regarding the build's status (see Figure 2).

Template for Jenkins Jobs for PHP Projects
Click here for larger image

Figure 2. Reviewing a Project's Build Status

This interface provides a bevy of useful information about the build, including the latest commit message and a variety of status updates pertaining to the plugins executed as defined by the Template for Jenkins Jobs for PHP Projects' configuration file.

Reviewing Project Statistics

After completing a build a list of useful graphs (known as plots) will also be at your disposal, summarizing the total lines of code found in the project, the number of code structures (classes, methods, functions, etc.), various test targets (classes, methods, etc.), the average length of classes and methods, and much more. Figure 3 presents a screenshot depicting the total lines of code found in a new project.

Template for Jenkins Jobs for PHP Projects
Click here for larger image

Figure 3. Reviewing the Total Lines of Code Found in Your Project

Documentation Generation

Jenkins will by default generate API and code coverage documentation, in addition to a Web-based code browser. The documentation is placed in respective directories found in your project's build directory. You can determine whether these generation features are enabled and additionally set the default directories from within your project's configuration interface (see Figure 4).

Template for Jenkins Jobs for PHP Projects
Click here for larger image

Figure 3. Enabling Documentation Generation


Like PHPUnit, Git and XDebug, Jenkins and the Template for Jenkins Jobs for PHP Projects project offer PHP developers another great solution for effectively and efficiently building complex PHP-driven applications. Are you currently using Jenkins for your PHP applications? Tell us about your experiences in the comments!

About the Author

Jason Gilmore is founder of the publishing, training, and consulting firm He is the author of several popular books "Easy PHP Websites with the Zend Framework", "Easy PayPal with PHP", and "Beginning PHP and MySQL, Fourth Edition". Follow him on Twitter at @wjgilmore.