# How to set RAILS\_ENV for different directories (fcgid)

**URL:** <https://www.ruby-forum.com/t/how-to-set-rails-env-for-different-directories-fcgid/67198>\
**Category:** Rails\
**Created:** [September 1, 2006, 11:41am UTC](https://www.ruby-forum.com/t/how-to-set-rails-env-for-different-directories-fcgid/67198 "2006-09-01T11:41:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 1, 2006, 11:41am UTC](https://www.ruby-forum.com/t/how-to-set-rails-env-for-different-directories-fcgid/67198/1 "2006-09-01T11:41:38Z")

</div>

Hello!

I want to use the same application in two environments (production and  
development) on the same server (apache2 with fcgid) in different  
(aliased) directories.

Is there a way to specify RAILS\_ENV inside my directives? I  
have the line  
DefaultInitEnv RAILS\_ENV production  
in my httpd.conf but I want one of the directories to be development.

Setting the ENV var directly in environment.rb is not an option because  
I update the production server via SVN but need to keep environment.rb  
in my repository.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 1, 2006, 12:47pm UTC](https://www.ruby-forum.com/t/how-to-set-rails-env-for-different-directories-fcgid/67198/2 "2006-09-01T12:47:59Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Setting the ENV var directly in environment.rb is not an option because  
> I update the production server via SVN but need to keep environment.rb  
> in my repository.

You could make the enviroment.rb more dynamic, i.e. compute the value  
for  
RAILS\_ENV from the current path. A hack but all ruby:

> RAILS\_ENV = case `hostname`.chomp  
> when “myserver”: /myproduction\_dir/.match(File.expand\_path(RAILS\_ROOT)) ? ‘production’ : 'development  
> else ‘development’  
> end

Or something along these lines.

## zsombor

Company - [http://primalgrasp.com](http://primalgrasp.com)  
Thoughts - [http://deezsombor.blogspot.com](http://deezsombor.blogspot.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 1, 2006, 12:47pm UTC](https://www.ruby-forum.com/t/how-to-set-rails-env-for-different-directories-fcgid/67198/3 "2006-09-01T12:47:59Z")

</div>

Hi,

I had the same problem. Unfortunately my solution was to change the  
environment.rb for the production app.

In Apache I have two virtual hosts, and I put the following in the  
staging defination :

SetEnv RAILS\_ENV development

and in the production host I put :

SetEnv RAILS\_ENV production

But for some reason that does not work. Maybe someone can tell us why  
this solution does not work.

Kind Regards  
Hamza
