Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6326485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:06:02+00:00 2026-05-24T17:06:02+00:00

I have 2 environments, production and staging , and I am using Capistrano with

  • 0

I have 2 environments, production and staging, and I am using Capistrano with capistrano-ext gem.

When I deploy to staging using Capistrano and restart passenger, I would like the deployed application to run in staging however it runs in the default production

I tried setting:

set :rails_env, "staging"

in my deploy recipe, but this had no effect.

I am aware this can be done by setting a virtual host in Apache, but I am using shared hosting, so don’t have access. My host offers this advice:

add the following to environment.rb: ENV[‘RAILS_ENV’] = ‘staging’

but this doesn’t help me automate the process with Capistrano.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:06:03+00:00Added an answer on May 24, 2026 at 5:06 pm

    You can use a capistrano hook to create files on the server or symlink them in from e.g. shared/ when deploying.

    For Rails 2.3:

    On your web host, create the file shared/preinitializer.rb:

    ENV['RAILS_ENV'] = 'staging'
    

    Then add this to your Capfile (or possibly config/deploy.rb if you’re using a newer version of capistrano with Rails 2.x:

    after 'deploy:symlink', 'localize:copy_shared_configurations'
    namespace :localize do
      desc 'copy shared configurations to current'
      task :copy_shared_configurations, :roles => [:app] do
        # I put database.yml here to keep deployed db credentials out of git
        %w[
          preinitializer.rb
        ].each do |f|
          run "ln -nsf #{shared_path}/#{f} #{current_path}/config/#{f}"
        end
      end
    end
    

    For Rails 3

    Due to the changes in Rails 3’s initialization sequence, config/preinitializer.rb is not loaded until after config/environment.rb is loaded. So for Rails 3, you want to modify config/environment.rb only on the server. You could do this with a similar setup like Rails 2 above, but using a symlinked copy of config/environment.rb, and adding the step of deleting the existing file before trying to symlink.

    Another option would be to overwrite the environment.rb on the server from capistrano. In your config/deploy.rb:

    after 'deploy:symlink', 'localize:munge_environment'
    namespace :localize do
      desc 'munge environment.rb to set staging environment'
      task :munge_environment, :roles => [:app] do
        new_env = "ENV['RAILS_ENV'] = 'staging'\n" + File.read(Rails.root.join('config', 'environment.rb'))
        put new_env, "#{current_path}/config/environment.rb"
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a series of web services that live in different environments (dev/qa/staging/production) that
I have the occasion to produce Drupal web sites using development, staging, and production
I've deployed my app on to a Ubuntu VPS using Capistrano, nginx/ Passenger and
I have 2 environments for my app on heroku: staging and production, and I'm
I have a application.ini like this [production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 includePaths.library
At my company, we have tiered environment for our web applications (development, staging, production).
As most production environments we have setup something to send us a notification if
I have a VB6's Application that is in production environment right now, this application
I have a three-tier application which is installed in corporate environments. With every server
I have a website that is deployed between 3 different environments - Dev, Stage,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.