OSX阿帕奇:允许PHP脚本的shell命令的执行 - 包括路径 [英] OSX Apache : allow execution of shell command for PHP script - include path
问题描述
我运行OSX的服务器,需要执行一个网站 pdftotext
,它安装在的/ usr / local / bin目录
。然而,似乎是在Apache路径不是命令的问题。
I am running a website on OSX server, that needs to execute pdftotext
, which is installed in /usr/local/bin
. However, there seems to be an issue with the command not being in the Apache path.
我第一次证实了我可以执行shell脚本。 < PHP了shell_exec('WHOAMI'); ?方式>
收益 _www
I first confirmed that I can execute shell scripts. <?php shell_exec('whoami'); ?>
returns _www
.
然而,当我运行以下命令:
However, when I run the following :
$cmd = 'has pdftotext 2>&- || echo 1';
$out = shell_exec($cmd);
echo $out;
返回1,这意味着它无法访问的命令。
it returns "1" meaning it cannot access the command.
从终端同样的命令运行没有返回值(我也没有任何问题访问程序)。
The same command run from terminal returns nothing (I can access the program without any issue).
当我运行了shell_exec('ENV'2&GT;&安培; 1。)
的/ usr / local / bin目录
确实不在路径。我在哪里可以设置它的Apache2 OSX山狮服务器上?
When I run shell_exec('env'."2>&1")
/usr/local/bin
is indeed not in the path. Where do I set it for Apache2 on OSX Mountain Lion Server ?
请参见下面
推荐答案
我找到了答案,这里怎么修改Apache的路径: https://gist.github.com/thebigdog/5208619
I found the answer as to how to modify the Apache PATH here: https://gist.github.com/thebigdog/5208619
我需要修改 /System/Library/LaunchDaemons/org.apache.httpd.plist
,加入
<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
现有&LT;密钥GT; EnvironmentVariables&LT; /键&GT;
定义。那么到底它是这样的:
to the existing <key>EnvironmentVariables</key>
definition. So in the end it looked like this:
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
<key>SERVER_INSTALL_PATH_PREFIX</key>
<string>/Applications/Server.app/Contents/ServerRoot</string>
<key>XPC_SERVICES_UNAVAILABLE</key>
<string>1</string>
</dict>
一旦我重新启动Apache服务器,添加路径和shell命令被正确执行。
Once I restarted the Apache server, the path was added and the shell command was executed properly.
这篇关于OSX阿帕奇:允许PHP脚本的shell命令的执行 - 包括路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!