Deploying PHP with Capistrano

I stumbled across a post about Automated PHP Deployment With Capistrano and it inspired me to set up Capistrano for a PHP site I maintain. Capistrano makes makes deploying my Rails applications painless. The deployment process for the PHP code was painful.

I started with the deploy.rb file mentioned in the article. I ended up overriding :update_code instead of :deploy. Initially I tried using the default deploy task from standard.rb but :update_code was failing because it couldn’t create a symbolic link. I copied :update_code to my script and modified it to created the links to shared code for my application.

desc "Get code from SVN and create symlinks to shared resources"
task :update_code, :except => { :no_release => true } do
  on_rollback { delete release_path, :recursive => true }

  source.checkout(self)

  run <<-CMD
    ln -nfs #{shared_path}/system #{release_path}/system &&
    ln -nsf #{shared_path}/gallery #{release_path}/gallery &&
    ln -nsf #{shared_path}/albums #{release_path}/albums
  CMD
 
  # uncache the list of releases, so that the next time it is called it will
  # include the newly released path.
  @releases = nil

I also needed to override :restart to do nothing.

desc "Override default restart behavior"
task :restart do
  # do nothing since we're PHP+Apache
end

Now deployment is as simple as cap deploy.
And if I goof something up cap rollback can save the day.

Advertisements
Posted in capistrano, php

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: