Capistrano is written in Ruby and offers up a basic DSL from which you can craft quite flexible deployment scripts. [...] That said, it’s very flexible. In my current setup I have it deploying to multiple environments (dev, staging, production), building code (think Phing), running tests on the servers before finalising the deploy and then restarting worker processes on completion.
He starts by introducing some of the commands that you can perform with the "cap" command line client and links to an example PHP project structure you cn base your deployment off of. He also includes a bit about multi-stage deployments, tag (version) selection and the full source of his build script.