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  Meta: 0 comments, permalink

Permission Denied errors with Capistrano 2.1

Getting "permission denied" errors in Capistrano 2.1 and can't explain why? Me too. Adding this to deploy.rb seems to fix it:

default_run_options[:pty] = true

Explanation here.

Tags: capistrano  Meta: 0 comments, permalink

Problems using Capistrano without a domain name

When using an ip address in the subversion url in deploy.rb, I kept running into timeouts when trying to deploy. As far as I can tell, capistrano needs to access the repository from both your local machine and the server. This is a problem because in most cases, my local machine will only recognize the server's external ip, and the server will only recognize it's internal ip. To get around it, I put a fake domain in my /etc/hosts file pointing to the external ip, and the same domain in the /etc/hosts file of the server pointing to 127.0.0.1. I then use that domain in the subversion url. The only headache there is that anyone who needs to deploy will also need an entry in their hosts file. I'm hoping to stumble upon a better solution soon.

Tags: capistrano  Meta: 0 comments, permalink

Rails setup and deployment with Capistrano 2.0 on Ubuntu 7.04 (Feisty)

A very specific post here to serve as a reminder the next time I have to do this: Setting up Ubuntu 7.04 with rails, Apache 2.2, mongrel (clustered), MySQL5, subversion, and deploying with capistrano 2.0. So bleeding edge!

Tags: capistrano  Meta: 5 comments, permalink

Using deprec when rails stack already installed

Sometimes I just want to set up version control and deployment on a server that already has the rails stack installed...

Tags: capistrano  Meta: 0 comments, permalink

cap disable_cms

Capistrano provides a handy "disable_web" task, which (with the proper rewrite rules) can take down the entire site. But sometimes I just want to take down the CMS (or admin side, or backend, or whatever you want to call it). This is how I do it.

Tags: capistrano  Meta: permalink

Deploying with Capistrano on Webfaction

The way webfaction handles your rails setup with fancy point and click hand-holding is great. Until you want to set your site up to use Capistrano. The problem boils down to two major issues:

  1. The root of your app on the server is setup automatically and is owned by root. You can't change it.
  2. The server wants to start your site with an autostart.cgi script.

There's probably a better way to do this, but here's how I set things up...

Tags: capistrano  Meta: permalink

Modifying the number of mongrels after deploying with deprec

In an effort to document everything I do that I had to dig up information for, comes this ridiculous post with a convoluted title. I had a few sites deployed using deprec. I set them up to use 4 mongrel instances, but now wanted to change that. Here's the steps I took...

Tags: capistrano  Meta: 2 comments, permalink