Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting environment variables for Phusion Passenger applications

I've set up Passenger in development (Mac OS X) and it works flawlessly. The only problem came later: now I have a custom GEM_HOME path and ImageMagick binaries installed in "/usr/local". I can put them in one of the shell rc files that get sourced and this solves the environment variables for processes spawned from the console; but what about Passenger? The same application cannot find my gems when run this way.

like image 896
mislav Avatar asked Sep 17 '08 02:09

mislav


People also ask

What does Phusion Passenger do?

Phusion Passenger® is an open source web application server. It handles HTTP requests, manages processes and resources, and enables administration, monitoring and problem diagnosis. Passenger is very easy to use, makes deploying in production much easier and is scalable.

Why do we configure the environmental variables to use Java?

Environment variables are useful to store system-wide values, for examples, PATH : the most frequently-used environment variable, which stores a list of directories to search for executable programs. OS : the operating system.

What is passenger nginx?

The Passenger Nginx module registers Passenger-specific configuration options inside Nginx. You, the administrator, configure Passenger by adding Passenger-specific configuration options to the Nginx configuration file. Restart or reload Nginx to apply any configuration changes.


3 Answers

I know of two solutions. The first (documented here) is essentially the same as manveru's—set the ENV variable directly in your code.

The second is to create a wrapper around the Ruby interpreter that Passenger uses, and is documented here (look for passenger_with_ruby). The gist is that you create (and point PassengerRuby in your Apache config to) /usr/bin/ruby_with_env, an executable file consisting of:

#!/bin/bash
export ENV_VAR=value
/usr/bin/ruby $*

Both work; the former approach is a little less hackish, I think.

like image 92
Ben Scofield Avatar answered Sep 22 '22 06:09

Ben Scofield


Before you do any requires (especially before requiring rubygems) you can do:

ENV['GEM_HOME'] = '/foo'

This will change the environment variable inside this process.

like image 25
manveru Avatar answered Sep 23 '22 06:09

manveru


I found out that if you have root priviledges on computer then you can set necessary environment variables in "envvars" file and apachectl will execute this file before starting Apache.

envvars typically is located in the same directory where apachectl is located - on Mac OS X it is located in /usr/sbin. If you cannot find it then look in the source of apachectl script.

After changing envvars file restart Apache with "apachectl -k restart".

like image 30
Raimonds Simanovskis Avatar answered Sep 20 '22 06:09

Raimonds Simanovskis