PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Idiot-Proof Deployment with Phing

Note: This article was originally published at Planet PHP on 12 May 2011.
Planet PHP
disclaimer: I am not underestimating the universe's ability to produce idiots, the point I'm trying to make is that I haven't managed to make any deploy mistakes using this approach. Yet.

Once upon a time, a long time ago, I went onto a conference stage for the very first time and said that I thought I might be the world's ditsiest PHP developer. I actually still think that is pretty true, and if you work with me then you will know that I mostly break and fix things in approximately equal measure. With this in mind, when I launched my own product recently (BiteStats, a thing to automatically email you a summary of your analytics stats every month), I knew that I would need a really robust way of deploying code. I've been doing a few different things for a few years, and I've often implemented these tools with or for other organisations, but I don't have much code in production in my own right, weirdly. I decided Phing was the way to go, got it installed, and worked out what to do next.

build.xml



I created a file called build.xml in the root of my project directory, and initially it contained only the following:

version="1.0" encoding="UTF-8"?
name="bitestats" basedir="." default="deploy"
A A name="builddir" value="./build" /


A
That default attribute says which task to run if no task is specified, and the property tag initialises a variable I'll need in a couple of places later on. In fact it's the build directory, a directory that will be used to hold all the artefacts of the build.

Tasks



Tasks are defined in the build file, inside the project tag. I have two really simple ones which I think most projects have: build and clean. These create the build directory ready for me to use when I run other tasks, and remove it again. So with those included, my file now looks like this:

version="1.0" encoding="UTF-8"?
name="bitestats" basedir="." default="deploy"
A A name="builddir" value="./build" /

A A name="clean"
A A A A A A

Truncated by Planet PHP, read more at the original (another 10120 bytes)