Modifying $PATH for PHP system() calls

孤人 提交于 2019-12-24 16:37:10

问题


I need to modify the $PATH on my mac so that PHP system() calls will recognize it.

So far I've edited the /etc/profile to include the line:

export PATH=$PATH:/Applications/MAMP/Library/bin

but if I do system('echo $PATH'); in PHP the new path doesn't show up.


回答1:


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 */

http://php.net/putenv



来源:https://stackoverflow.com/questions/5144238/modifying-path-for-php-system-calls

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