Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the Ruby on Rails application environment using Capistrano on Phusion Passenger

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.

like image 829
dangerousdave Avatar asked Apr 24 '11 11:04

dangerousdave


People also ask

What is Capistrano in Rails?

Capistrano is a tool for deploying applications using deployment scripts. To perform deployments, you can use predefined tasks or create custom Rake tasks. RubyMine allows you to quickly run Capistrano tasks with double Ctrl and configure Capistrano run options using run configurations.

What is Capistrano gem?

Capistrano is a framework for building automated deployment scripts. Although Capistrano itself is written in Ruby, it can easily be used to deploy projects of any language or framework, be it Rails, Java, or PHP.

How does Capistrano work?

How does Capistrano work? Capistrano is a framework written in Ruby that provides automated deploy scripts. It connects to your web server via SSH and executes a bunch of tasks that will make your app ready to shine.


1 Answers

What you are doing when you setting :rails_env, "staging" environment is setting the environment for the migration. In other words, it's a environment that is only set when you're running capistrano. If I understand you correctly, you want to change the environment when running your app, not deploying.

In order to answer your question, I'll need to know how you are launching (starting) your application.

If you're using Phusion Passenger, you'll need to edit your RAILS_ENV for Passenger

Given that you're in a shared environment, you'll probably want to go with the .htaccess route.

like image 97
Cory Avatar answered Oct 11 '22 21:10

Cory