How to set $PATH for php exec or shell_exec

一个人想着一个人 提交于 2019-12-23 10:01:27

问题


I have set the PATH to run ant and it is working on putty but on php exec it is returning sh ant command not found i have tried to set PATH by export PATH=/usr/ant/bin


回答1:


Call putenv before exec:

putenv('PATH=/usr/ant/bin');



回答2:


Environment variables are set in the context of a user session. If you want to set the variable for the PHP user you should check what user apache runs under (typically apache), and add

export PATH=/usr/ant/bin

to

/home/apache/.bashrc

So that the path is set for every session the user apache starts.



来源:https://stackoverflow.com/questions/10835923/how-to-set-path-for-php-exec-or-shell-exec

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