I'm running the app under Apache2 and Phusion Passenger.
Setting a UNIX shell environment variable in .bashrc, etc., doesn't work because the files are not sourced from Apache.
The way to do this is to set them within your Apache Virtual Host block using the SetEnv directive. For example, here is a vhost block for my app:
<VirtualHost *:80>Then in your application, typically in your config/environment.rb file, you would access this as:
ServerName www.example.com
SetEnv FOOBAR "foobar"
DocumentRoot "/mnt/myapp/current/public"
RailsEnv development
RailsAllowModRewrite off
<directory "/mnt/myapp/current/public">
Order allow,deny
Allow from all
</directory>
</VirtualHost>
my_variable = ENV['FOOBAR']
This works great but ONLY with version 2.2.3 or higher of the Passenger Gem. To see what version you have installed:
$ gem list passengerand to update:
$ sudo gem update passenger
$ sudo passenger-install-apache2-module
No comments:
Post a Comment