简体   繁体   English

为什么PHP exec()命令没有运行?

[英]Why doesn't PHP exec() command doesn't run?

I have a very simple PHP script to try to use the exec command. 我有一个非常简单的PHP脚本来尝试使用exec命令。 The code is 该代码是

 <?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo("test<br>");
echo exec('whoami');
echo("test");
?>

However when I access the page, it just prints out: 但是,当我访问该页面时,它只会打印出来:

test
test

It does not print the output from "whoami" command, which when run from command line displays 它不打印“ whoami”命令的输出,该命令从命令行运行时显示

me

What is the problem here? 这里有什么问题? I cannot work it out. 我无法解决。

Thanks a lot! 非常感谢!

(on a system with the "whoami" executable in the path) (在路径中带有“ whoami”可执行文件的系统上)

PATH , like all environment variables, is not system-wide but ultimately per-process . 像所有环境变量一样, PATH不是系统范围的,而是最终每个进程的

That is, though your typical bash session may well include the path to this executable in PATH , the environment in which your PHP script is running (say, an Apache CGI context) does not. 也就是说,尽管您的典型bash会话很可能在PATH包含此可执行文件的PATH ,但运行PHP脚本的环境(例如Apache CGI上下文)却没有。 This may be for any reason. 这可能是出于任何原因。

Provide an absolute path to whoami , instead. 提供一条通往whoami的绝对路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM