How do I add paths to the Apache PATH variable?

三世轮回 提交于 2019-12-17 07:38:25

问题


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

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!


回答1:


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:

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

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.

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.




回答2:


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

export PATH=<your php cli path>

and restart apache




回答3:


This question is old, but in case it helps others, if you are using Windows with mod_fcgid check if you have the FcgidInitialEnv set in your httpd.conf, and remove it to adopt the System PATH.




回答4:


Macports Apache 2.4 install

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

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

2.Edit 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

4.sudo port load apache2

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.

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



来源:https://stackoverflow.com/questions/2837697/how-do-i-add-paths-to-the-apache-path-variable

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