Fork me on GitHub

Using the multistage extension

Capistrano provides a Multistage extension which allows to use a different deployment strategy for different scenarios. For instance, for your application, you might have two servers: one for production, where the “live” code is, and one for staging, where you can test features out without risk of affecting anything critical.


In order to use the Multistage extension, you need to add the following lines to your deploy.rb file:

set :stages,        %w(production staging)
set :default_stage, "staging"
set :stage_dir,     "app/config"
require 'capistrano/ext/multistage'

The first parameter :stages configures your different stages. In that case, we just have two stages production, and staging which is also the default stage. The :stage_dir parameter allows to configure the path to your configuration files for each stage.


In order to configure each stage, you must create a configuration file per stage. In that case, you have to create both app/config/production.rb and app/config/staging.rb files.

The production.rb file contains your production settings:

server '', :app, :web, :primary => true

The staging.rb file contains your staging settings:

server '', :app, :web, :primary => true

That’s it!


As you configured the :default_stage parameter with staging, all tasks will be run with your staging settings.

But now, you can run cap production deploy to deploy your application to your production server, and it’s the same pattern for all tasks:

cap stage taskname

Where stage can be either staging, or production in our example.

Found a typo? Something is wrong in this documentation? Just fork and edit it !