为 Phusion Passenger 应用程序设置环境变量
我已经在开发中设置了 Passenger (Mac OS X),它运行得非常完美。 唯一的问题出现了:现在我有一个自定义的 GEM_HOME
路径,并且 ImageMagick 二进制文件安装在 "/usr/local"
中。 我可以将它们放入获取源的 shell rc 文件之一中,这解决了从控制台生成的进程的环境变量问题; 但乘客呢? 以这种方式运行时,相同的应用程序无法找到我的宝石。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现如果你在计算机上有 root 权限,那么你可以在“envvars”文件中设置必要的环境变量,apachectl 将在启动 Apache 之前执行该文件。
envvars 通常位于 apachectl 所在的同一目录中 - 在 Mac OS X 上,它位于 /usr/sbin 中。 如果找不到它,请查看 apachectl 脚本的源代码。
更改 envvars 文件后,使用“apachectl -k restart”重新启动 Apache。
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".
在执行任何要求之前(特别是在要求 rubygems 之前),您可以执行以下操作:
这将更改此进程内的环境变量。
Before you do any requires (especially before requiring rubygems) you can do:
This will change the environment variable inside this process.
我知道有两种解决方案。 第一个(记录在此处)本质上与manveru的相同—直接在代码中设置 ENV 变量。
第二个是围绕 Passenger 使用的 Ruby 解释器创建一个包装器,并记录在 此处(查找passenger_with_ruby)。 要点是您创建(并将 Apache 配置中的 PassengerRuby 指向)/usr/bin/ruby_with_env,这是一个可执行文件,其中包含:
两者都有效; 我认为前一种方法不那么老套。
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:
Both work; the former approach is a little less hackish, I think.
我也遇到过这个问题。 似乎乘客没有传递使用
SetEnv
apache 指令 - 这是不幸的。也许可以在environment.rb或boot.rb中设置环境变量(假设您正在谈论Rails应用程序;我不熟悉Rack,但想必它具有类似的功能)
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)