php 如何向 Apache PATH 变量添加路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2837697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:50:03  来源:igfitidea点击:

How do I add paths to the Apache PATH variable?

phpapachepath

提问by joelataylor

I've set in my custom.conf file in apache2 this:

我在 apache2 中的 custom.conf 文件中设置了以下内容:

SetEnv PATH $PATH:/opt/local/lib/mysql5/bin:/this-is-a-test

However it's not working. When I call:

但是它不起作用。当我打电话时:

$hey = shell_exec('env'." 2>&1"); var_dump($hey);

I get:

我得到:

... PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/opt/local/bin

Can anyone help? I'm on Mac using Macports for my development environment. Thanks!

任何人都可以帮忙吗?我在 Mac 上使用 Macports 作为我的开发环境。谢谢!

采纳答案by Michael Aaron Safyan

That seems awfully strange to me that you are trying to set the PATH from within Apache. Instead, you should be setting the PATH for your system. There are several ways to do this in Mac OS X:

您试图从 Apache 内部设置 PATH 对我来说似乎非常奇怪。相反,您应该为您的系统设置 PATH。在 Mac OS X 中有几种方法可以做到这一点:

User-specific
For a single user, you can edit ~/.profile and add:

User-specific
对于单个用户,您可以编辑 ~/.profile 并添加:

export PATH="$PATH":/opt/local/lib/mysql5/bin:/this-is-a-test

Or you can create/edit ~/.MacOSX/environment.plist and define the PATH that way.

或者您可以创建/编辑 ~/.MacOSX/environment.plist 并以这种方式定义 PATH。

System-wide
On newer versions of Mac OS X, there is a file named "/etc/paths" and there is a folder named "/etc/paths.d" that allow you to extend the default paths. Basically, you would create a file in "/etc/paths.d" that lists all the paths that you wish to add to the default paths. On versions of Mac OS X that do not support this (you can tell based on whether "/usr/libexec/path_helper" exists), one can edit the default paths for all users by placing the export statement above in /etc/profile.

系统范围
在较新版本的 Mac OS X 上,有一个名为“/etc/paths”的文件和一个名为“/etc/paths.d”的文件夹,允许您扩展默认路径。基本上,您将在“/etc/paths.d”中创建一个文件,其中列出了您希望添加到默认路径的所有路径。在不支持此功能的 Mac OS X 版本上(您可以根据“/usr/libexec/path_helper”是否存在来判断),可以通过将上面的 export 语句放在 /etc/profile 中来编辑所有用户的默认路径。

回答by diyism

for ubuntu server, in /etc/apache2/envvars, for centos server, in /etc/sysconfig/httpd, to add:

对于ubuntu服务器,在/etc/apache2/envvars中,对于centos服务器,在/etc/sysconfig/httpd中,添加:

export PATH=<your php cli path>

and restart apache

并重新启动apache

回答by Dan

This question is old, but in case it helps others, if you are using Windowswith mod_fcgidcheck if you have the FcgidInitialEnvset in your httpd.conf, and remove it to adopt the System PATH.

这个问题是旧的,但在情况下,它可以帮助别人,如果你正在使用的Windows使用mod_fcgid,如果你有检查FcgidInitialEnv你的设置httpd.conf,并删除它采用的系统路径。

回答by Stephen Hamilton

Macports Apache 2.4 install

Macports Apache 2.4 安装

The only way I have found to get this to stick on a reboot is to edit the macports apache2.plist. Steps I took:

我发现让它坚持重新启动的唯一方法是编辑 macports apache2.plist。我采取的步骤:

1.sudo /opt/local/sbin/apachectl stop

1.sudo /opt/local/sbin/apachectl stop

2.Edit plist: /opt/local/etc/LaunchDaemons/org.macports.apache2/org.macports.apache2.plist

2.编辑plist: /opt/local/etc/LaunchDaemons/org.macports.apache2/org.macports.apache2.plist

And add:

并添加:

<key>EnvironmentVariables</key>
<dict>
    <key>PATH</key>
    <string>/usr/bin:/bin:/usr/sbin:/sbin:{add paths here}</string>
</dict>

3.sudo port unload apache2

3.sudo port unload apache2

4.sudo port load apache2

4.sudo port load apache2

5.sudo /opt/local/sbin/apachectl start

5.sudo /opt/local/sbin/apachectl start

Paths stick on a reboot. However the plist will probably be wiped on the next macports update I do.

路径坚持重新启动。但是 plist 可能会在我做的下一个 macports 更新中被擦除。

EDIT : And this proved to be true. I upgraded to Mojave with an associated macports update, and had to re-apply the steps above

编辑:事实证明这是真的。我使用相关的 macports 更新升级到 Mojave,并且不得不重新应用上述步骤