macos mac 上 apache2 的 $PATH 环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6833939/
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
$PATH environment variable for apache2 on mac
提问by Chuck Burgess
I am trying to get apache/php to recognize the path to my git. I have been researching and looking in all corners of the web and cannot find how to do this. Basically, no matter what I try, when I run echo phpinfo();
the Apache Environment
path does not change from /usr/bin:/bin:/usr/sbin:/sbin
. And when I run system('echo $PATH');
in PHP, it reads the same.
我试图让 apache/php 识别我的 git 的路径。我一直在研究和寻找网络的各个角落,但找不到如何做到这一点。基本上,无论我尝试什么,当我运行时echo phpinfo();
,Apache Environment
路径都不会从/usr/bin:/bin:/usr/sbin:/sbin
. 当我system('echo $PATH');
在 PHP 中运行时,它读取相同的内容。
System Information:
系统信息:
- Mac OSX (Lion)
- Apache 2 (running as _www)
- PHP 5.3.6
- Mac OSX (Lion)
- Apache 2(作为 _www 运行)
- PHP 5.3.6
Here is what I have tried editing so far:
这是我到目前为止尝试编辑的内容:
- /etc/profile
- ~/.bash_profile
- ~/.profile
- /etc/path
- /etc/path.d/{NEW_FILE}
- /etc/配置文件
- ~/.bash_profile
- ~/.profile
- /etc/路径
- /etc/path.d/{NEW_FILE}
Nothing I have tried so far has changed the $PATH
variable. Any ideas?
到目前为止,我没有尝试过任何改变$PATH
变量的方法。有任何想法吗?
SOLUTION
解决方案
So here is the final solution. I edited the
所以这是最终的解决方案。我编辑了
/System/Library/LaunchDaemons/org.apache.httpd.plist
and added
并添加
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin</string>
</dict>
回答by Monolo
回答by lqez
Did you update the PATH environment variable of user '_www'? Apache will read environment variables from the user runs itself. Or, it looks like you didn't restart apache after updating PATH environment variable.
您是否更新了用户“_www”的 PATH 环境变量?Apache 会从用户运行中读取环境变量。或者,您似乎在更新 PATH 环境变量后没有重新启动 apache。
- Check out the older discussion :
And if you want to modify environment variable in PHP, getenv() and putenv() can be a better choice.
如果你想在 PHP 中修改环境变量,getenv() 和 putenv() 可能是更好的选择。
- getenv : http://php.net/manual/en/function.getenv.php
putenv : http://www.php.net/manual/en/function.putenv.php
$path = getenv('PATH'); putenv( "PATH=$path:/new_path_that_you_want_to_add" );
- getenv : http://php.net/manual/en/function.getenv.php
putenv : http://www.php.net/manual/en/function.putenv.php
$path = getenv('PATH'); putenv( "PATH=$path:/new_path_that_you_want_to_add" );
回答by Kiers_M
Important note for El Capitan (Apologies for the new answer - I don't have enough Rep to comment)
El Capitan 的重要说明(为新答案道歉 - 我没有足够的代表发表评论)
On OSX 10.11, the /System/Library folder is protected, so the files can't be edited.
在 OSX 10.11 上,/System/Library 文件夹受到保护,因此无法编辑文件。
You need to:
你需要:
- Reboot into Recovery Mode (hold CMD + r after the startup sound)
- Once in recovery mode, go to Utilities > Terminal
- Run:
csrutil disable
- Reboot back into OSX - you should now be able to change the files
- Once done, go back to recovery mode and run
csrutil enable
- 重新启动进入恢复模式(在启动声音后按住 CMD + r)
- 进入恢复模式后,转到实用程序 > 终端
- 跑:
csrutil disable
- 重新启动到 OSX - 您现在应该能够更改文件
- 完成后,返回恢复模式并运行
csrutil enable
Hope that helps
希望有帮助
回答by Ray Hunter
I created this gist that helped me out from the information above:
我创建了这个要点,帮助我从上面的信息中解脱出来:
https://gist.github.com/srayhunter/5208619
https://gist.github.com/srayhunter/5208619
My problem was that PHP was not finding a program that we had installed under /usr/local/bin. Once we did the above it all worked and played nice on mac osx.
我的问题是 PHP 没有找到我们在 /usr/local/bin 下安装的程序。一旦我们完成了上述所有工作,并且在 mac osx 上运行良好。
回答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 Marek
A similar problem to what I was having installing Derby. The way I solved it was by opening TextEdit. Select File > Open at this point press Shift + Command + . , this will allow you to view all the documents. Head to the user directory and search for a file called ".profile" . Open it and add the export VARIABLE= Value line for example:
与我在安装 Derby 时遇到的类似问题。我解决它的方法是打开 TextEdit。选择“文件”>“打开”,此时按 Shift + Command + 。,这将允许您查看所有文档。前往用户目录并搜索名为“.profile”的文件。打开它并添加 export VARIABLE= Value 行,例如:
export DERBY_HOME=/opt/local/share/java/derby/
导出 DERBY_HOME=/opt/local/share/java/derby/
Save the document and restart your terminal to see if the changes went into affect.
保存文档并重新启动终端以查看更改是否生效。