Setting environment variables for Phusion Passenger applications

醉酒当歌 提交于 2019-12-04 06:21:09

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.

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.

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".

I've run into this issue as well. It appears that Passenger doesn't passthrough values set using the SetEnv apache directive - which is unfortunate.

Perhaps it might be possible to set environment variables in your environment.rb or boot.rb (assuming you're talking about a Rails app; I'm not familiar with Rack but presumably it has similar functionality)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!