Home  >  Article  >  Backend Development  >  一个很蛋疼的exec有关问题,求大侠解决…

一个很蛋疼的exec有关问题,求大侠解决…

WBOY
WBOYOriginal
2016-06-13 10:17:14825browse

一个很蛋疼的exec问题,求大侠解决……
我做一个在线编程的一个页面,要用到系统调用exec来取得用户写的程序的运行后的输出值,写的脚本基本如下:

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$command = "/var/program/userprogram";exec($command, $data);print_r($data);

(/var/program/)不是web的根目录
这个是经过简化的,我su 到apache用户后在命令行下执行php test.php能够成功的输出程序的执行数据,但是在WEB下去访问这个文件,却很奇怪的出现Array ( [0] => sh: /var/program/userprogram: Permission denied ) 。我很纳闷,同样的代码,在我自己的电脑上是没有问题的,不知道是不是因为有什么安全配置阻止了在其他目录下执行非系统命令的权限。另外,我把那个userprogram文件放到web根目录下,运行也是没问题的。。。

------解决方案--------------------
chmod 777 /var/program/userprogram 命令行下改改看
------解决方案--------------------
在linux 下执行 用的是执行者的权限
在apache下用的是apache 进程帐号的权限
------解决方案--------------------
用exec的方式很值得怀疑。做这种东西,估计要通过c,sokcet之类的来辅助以下。
------解决方案--------------------
echo get_current_user();

先看看当前运行的用户是什么
------解决方案--------------------
权限问题 apache帐号的权限不能执行那个程序
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn