Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phusion passenger not seeing environment variables?

We are running ubuntu servers with Nginx + Phusion Passenger for our rails 3.0x apps.

I have an environment variable set in /etc/environment on the test machines:

MC_TEST=true

If I run a console (bundle exec rails c) and output ENV["MC_TEST"] I see 'true'. But, if I put that same code on a page ( <%= ENV["MC_TEST"] %> ) it doesn't see anything. That variable does not exist.

Which leads me to question:

1 - What is the proper way to get environment variables into passenger with nginx (not apache SetEnv)?

2 - Why does Passenger not have a proper environment?

like image 871
phil Avatar asked May 11 '12 01:05

phil


2 Answers

Passenger fusion v4+ enables reading of environment variables directly from bashrc file. Make sure that bashrc lives in the home folder of the user under which passenger process is executed (in my case, it was ubuntu, for ec2 linux and nginx)

Here is the documentation which goes into details of bashrc

like image 94
nancyv233 Avatar answered Sep 21 '22 12:09

nancyv233


I've the same problem with you when use passenger with nginx and nginx init script on ubuntu. The reason is that I use sudo service nginx restart(installed by init script) to start up nginx and
it was running by root and the root did not get your login user environment variable. There are two solutions for this. One is running nginx manually.

sudo service nginx stop
sudo -E /path/to/your/nginx

one is add env to your nginx init script

export MC_TEST=true

The latter solution is somehow ugly, But it works. And I think the better way is found a configuration to tell the init script to preserve the login user env.

like image 45
raykin Avatar answered Sep 22 '22 12:09

raykin