Setting up a deployment / build / CI cycle for PHP projects

I've been through buildbot, CruiseControl.net, CruiseControl and Hudson. All though I really liked CruiseControl*, it was just too much of a hassle with really complex dependency cases. buildbot is not easy to set up, but it's got a nice aura (I just like python, that's all). But hudson won over the former three because:

  1. It's just easy to set up
  2. It's easy to customize
  3. It looks good and got nice overview functionality
  4. It got point-and-click updates, for itself and all installed plugins. This is a really nice feature, that I appreciate more and more

Caveat: I only ever used linux as base for the above mentioned build servers (CC.net ran on mono), but they should all - according to the docs - run cross-platform.

Setting up a hudson server

Prerequisites:

  • Java (1.5 will serve you just fine)
  • Read access to the subversion server (I have a separate account for the hudson user)

From here, it's just:

java -jar hudson.war

This will run a small server instance right off your console, and you should be able to browse the installation at your http://localhost:8080, if you don't have anything else running on that port in advance (you can specify another port by passing the --httpPort=ANOTHER_HTTP_PORT option to the above command) and everything went well in the 'installation' process.

If you go to the available plugins directory (http://localhost:8080/pluginManager/available), you'll find plugins for supporting your above mentioned tasks (subversion support is installed per default).

If that has whet you appetite, you should install a java application server, such as tomcat or jetty. Installation instructions are available for all major application servers

Update: Kohsuke Kawaguchi has constructed a windows service installer for hudson

Setting up a project in hudson

The links in the following walk-through assumes a running instance of hudson located at http://localhost:8080

  1. Select new Job (http://localhost:8080/view/All/newJob) from the menu on the left
  2. Give the job a name and tick Build a free-style software project on the list
  3. Pressing 'ok' will take you to the configuration page of the job. All the options have a little question mark besides them. Pressing this will bring up a help text regarding the option.
  4. Under the option group 'Source Code Management' you would be using Subversion. Hudson accepts both url access as well as local module access
  5. Under the option group 'Build Triggers', you would use 'Poll SCM'. The syntax used here is that of cron, so polling the subversion repository every 5 minutes would be */5 * * * *
  6. The process of building the project is specified under the option group 'Build'. If you already have an ant build file with all the targets you need, you're in luck. Just choose 'Invoke ant' and write the name of the target. The option group supports maven and shell commands as well out of the box, but there is also a plugin available for phing.
  7. Tick off additional build actions in 'Post Build Actions', such as e-mail notifications or archiving of build artefacts.

For setting up processes for which hudson have no plugins, you can either call them directly through a shell script from within the build setup, or you could write you own plugin

Pitfalls:

  • If you have it produce build artefacts, remember to have hudson clean up after itself in regular intervals.
  • If you have more than 20 projects set up, consider not displaying their build status as the default main page on hudson

Good luck!


The term you are looking for is "continous integration."

Here is an example of someone who uses GIT + phpundercontrol: http://maff.ailoo.net/2009/09/continuous-integration-phpundercontrol-git/

CruiseControl (which is a CI server), can use Hosted SVN/GIT as a source. So you can even use it with GitHub or Beanstalk or something else.

Then you can integrate that with the following kind of software:

  • PHPUnit
  • php-codesniffer
  • phpdocumentor
  • PHP Gcov
  • PHPXref
  • Yasca
  • etc.

You could also try this hosted CI: http://www.php-ci.net/hosting/create-project

Keep in mind though, that those tools need custom support if you integrate them yourself.

Have you also thought about project management and patch management?

You can use Redmine for project management. It has integrated continuous integration support, but only as client side (not as CI server).

Try using a hosted SVN/GIT/etc. solution, because they will cover your backups and keep their servers running, so you can focus on development.

For a tutorial on how to setup Hudson, see: http://toptopic.wordpress.com/2009/02/26/php-and-hudson/


I use Atlassian's Bamboo continous integration server for my main PHP project (along with their other products such as fisheye (repository browsing), jira (issue tracker) and clover (code coverage)).

It supports SVN and now supports Git and it has a great user interface. It is available for linux, windows and mac and can run standalone on its own tomcat server which is great for people (like me) who does not like to take days to setup their tools). Although it may look expensive, being a lone developer myself I purchased the starter kit license for 10$ (10$ by software). This is great for small teams and it is worth the look.


PHPTesting PHPCI This is nice, continuous integration server built in php.

Plus, its free and open source. :)

it has number of plugins..

PHPCI includes integration plugins for:

  • Atoum
  • Behat
  • Campfire
  • Codeception
  • Composer
  • Email
  • Grunt
  • IRC
  • PHP
  • Lint
  • MySQL
  • PDepend
  • PostgreSQL
  • PHP Code Sniffer
  • PHP Copy/Paste Detector
  • PHP Spec
  • PHP Unit
  • Shell Commands
  • Tar / Zip