为PHP system()调用修改$ PATH [英] Modifying $PATH for PHP system() calls
本文介绍了为PHP system()调用修改$ PATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在Mac上修改$ PATH,以便PHP system()调用能够识别它.
I need to modify the $PATH on my mac so that PHP system() calls will recognize it.
到目前为止,我已经编辑了/etc/profile,以包括以下行:
So far I've edited the /etc/profile to include the line:
export PATH=$PATH:/Applications/MAMP/Library/bin
但是如果我在PHP中执行system('echo $PATH');
,则不会显示新路径.
but if I do system('echo $PATH');
in PHP the new path doesn't show up.
推荐答案
使用putenv函数.例如,要将当前目录添加到$ PATH,可以使用以下代码:
Use the putenv function. For example, to add the current directory to the $PATH, one could use the following code :
<?php
putenv('PATH='.getenv('PATH').':.');
echo shell_exec('echo $PATH'); /* Prints the expected result */
这篇关于为PHP system()调用修改$ PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文