Deploying a PHP site with Capistrano 2

I had no idea how easy it was to deploy a PHP site with capistrano. Assuming you have control over where your web root is (i.e. it would be much harder on a shared host), pretty much all you have to do is overwrite the restart tasks and you're good to go.

Here's what I did in more detail:

Lets say I have a php site called php_site. At the bare minimum, I should have my directory structure set up like this:

php_site/config # => Config scripts that should not be hit through the browser
php_site/public # => Public scripts and files that are meant to be hit through the browser

Now I just have to create the capistrano files:

cd /path/to/php_site
capify .

Now I alter config/deploy.rb as normal. The only difference is I want to override the start/stop/restart tasks since there are no mongrel or fastcgi processes to worry about. Here's an example:

# ============================================================================
# REQUIRED VARIABLES
# ============================================================================

set :application, "php_site"
set :repository,  "svn+ssh://user@php_site.com/var/svn/php_site/trunk"

# ============================================================================
# ROLES
# ============================================================================

# Only one role for this php site, easy!
role :app, "php_site.com"

# ============================================================================
# OPTIONAL VARIABLES
# ============================================================================

set :user, "user"                         # defaults to the current user
set :deploy_to, "/var/www/#{application}" # defaults to /u/apps/#{application}

# ============================================================================
# TASKS
# ============================================================================

namespace :deploy do
  desc "Empty stub for restart task (PHP sites don't need to restart)"
  task :restart do
    puts "Done"
  end

  desc "Empty stub for start task (PHP sites don't need to start)"
  task :restart do
    puts "Done"
  end

  desc "Empty stub for stop task (PHP sites don't need to stop)"
  task :restart do
    puts "Done"
  end
end

Note: If you're getting strange permission errors, you may need to add this to deploy.rb (See http://www.mail-archive.com/capistrano@googlegroups.com/msg02817.html):

default_run_options[:pty] = true

In this case, my site needs to be configured with a document root of /var/www/php_site/current/public. Don't forget to reload apache (or whatever webserver you're running) after configuring that.

To set up the server, as usual, just run:

cap deploy:setup

Then deploy with

cap deploy

You shouldn't have to run deploy:cold since there are no processes to start or migrations to run. Although setting up a php site to use ActiveRecord migrations would be sweet...

Tags: capistrano deployment php  Meta: 0 comments, permalink

Comments

Leave a response

Comment