PHP+Capistrano+Shared Host = Easy Deployments
I wrote a Rails app that was deployed with Capistrano and I loved it. Every time I made a change, one file or a dozen, I could get all the files up in a single command. In addition, if anything was broken I could revert to the previous deploy with
While using Capistrano is considered a "standard" with Rails, it's something that I think should be used more with PHP as well. When I built my last website with PHP I reverted back to my FTP client deploys, and it was a nightmare. I worried about the order in which I uploaded each file and making sure I uploaded all of my changes.
I'm aware of the services like Beanstalk that let you do a
git push and will move the modified files for you. But, I'm not a big fan of sharing my entire repository or giving access to my server. Plus, I'm a little cheap, especially when I know I can write my own system for free. It may not be as fancy and it may require a little more work, but I like having complete control.
I don't want to explain how to make deployments with Capistrano. There are a lot of tutorials on the web that do a much better job than I can. So, if you're not familiar with Capistrano, you will need to follow a tutorial. The Capistrano Wiki has quite a few resources that you may find helpful.
However, there is one modification that is far different than most Capistrano tutorials. On my shared host, I wasn't allowed to change the
DocumentRoot for my primary domain. As a result, I had to create a symlink from
~/public_html to the latest release on every deploy. While it sounds difficult, it's actually very easy.
The Deployment Strategy
This is where all the magic of Capistrano takes place. It's where you get to decide what takes place and when. You can define your entire deploy strategy here and Capistrano will make sure it happens, every time.
The most important change to the default deployment is on line 38. It deletes the default
~/public_html directory and replaces it with a symlink to the latest release. A very simple command that makes the whole thing work.
The result is when I want to push the changes I made I can run
cap deploy and my entire application is uploaded. I don't have to worry about individual files, and if something breaks I can always return to the previous release with