为 Phusion Passenger 应用程序设置环境变量

发布于 2024-07-04 05:34:32 字数 232 浏览 12 评论 0原文

我已经在开发中设置了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

放飞的风筝 2024-07-11 05:34:32

我发现如果你在计算机上有 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".

挽清梦 2024-07-11 05:34:32

在执行任何要求之前(特别是在要求 ruby​​gems 之前),您可以执行以下操作:

ENV['GEM_HOME'] = '/foo'

这将更改此进程内的环境变量。

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.

无人问我粥可暖 2024-07-11 05:34:32

我知道有两种解决方案。 第一个(记录在此处)本质上与manveru的相同—直接在代码中设置 ENV 变量。

第二个是围绕 Passenger 使用的 Ruby 解释器创建一个包装器,并记录在 此处(查找passenger_with_ruby)。 要点是您创建(并将 Apache 配置中的 PassengerRuby 指向)/usr/bin/ruby_with_env,这是一个可执行文件,其中包含:

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

两者都有效; 我认为前一种方法不那么老套。

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.

温暖的光 2024-07-11 05:34:32

我也遇到过这个问题。 似乎乘客没有传递使用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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文