PHP 警告:shell_exec():无法执行“[command]”
PHP Warning: shell_exec(): unable to execute '[command]'
背景:我有一个 PHP 脚本调用 shell_exec
。目前我只想测试它是否有效,并且是 运行 通过它的基本命令。同一脚本的不同副本存在于同一服务器上的两个不同的 Web 应用程序中。两个应用程序的匿名身份验证都设置为 IUSR。
示例代码如下:
$output = shell_exec('dir 2>&1');
print_r($output);
在 IIS 中的一个网站上尝试它会得到所需的输出。但是,在另一个上,它不捕获任何输出,而是给出以下错误:
PHP Warning: shell_exec(): Unable to execute 'dir 2>&1' in C:\inetpub\webapp\script.php on line 4
关于这个错误我能找到的唯一信息来自 here:
With PHP on Windows, if you get the 'Warning: shell_exec()
[function.shell-exec]: Unable to execute' error, then you need to
check the permissions on file 'C:\WINDOWS\system32\cmd.exe'. You need
read/execute permission on this file. I would recommend using the
sysinternals Process Monitor 'procmon.exe' to confirm the user that is
trying to run 'cmd.exe'. Filter on 'Process Name' is 'php-cgi.exe' and
'Path' ends with 'cmd.exe'. Look at the event properties for the task
with the access denied error, and it will show you the 'Impersonating'
user name. This is usually the 'Internet Guest Account', often 'NT
AUTHORITY\IUSR'.
但这似乎不是权限问题。我不明白为什么它在网站上而不是另一个网站上工作。两个网站的匿名身份验证都设置为 IUSR。
此外,php.ini 中的 safe_mode
设置为 off
。
这里还有什么我需要检查的吗? cmd.exe 是否需要明确的 read/execute IUSR 权限?
事实证明,无论出于何种原因,IUSR 都是问题所在。我不能确切地知道为什么,但是将受影响网站的匿名身份验证更改为使用它工作的另一个用户。所以毕竟是权限相关的。
背景:我有一个 PHP 脚本调用 shell_exec
。目前我只想测试它是否有效,并且是 运行 通过它的基本命令。同一脚本的不同副本存在于同一服务器上的两个不同的 Web 应用程序中。两个应用程序的匿名身份验证都设置为 IUSR。
示例代码如下:
$output = shell_exec('dir 2>&1');
print_r($output);
在 IIS 中的一个网站上尝试它会得到所需的输出。但是,在另一个上,它不捕获任何输出,而是给出以下错误:
PHP Warning: shell_exec(): Unable to execute 'dir 2>&1' in C:\inetpub\webapp\script.php on line 4
关于这个错误我能找到的唯一信息来自 here:
With PHP on Windows, if you get the 'Warning: shell_exec() [function.shell-exec]: Unable to execute' error, then you need to check the permissions on file 'C:\WINDOWS\system32\cmd.exe'. You need read/execute permission on this file. I would recommend using the sysinternals Process Monitor 'procmon.exe' to confirm the user that is trying to run 'cmd.exe'. Filter on 'Process Name' is 'php-cgi.exe' and 'Path' ends with 'cmd.exe'. Look at the event properties for the task with the access denied error, and it will show you the 'Impersonating' user name. This is usually the 'Internet Guest Account', often 'NT AUTHORITY\IUSR'.
但这似乎不是权限问题。我不明白为什么它在网站上而不是另一个网站上工作。两个网站的匿名身份验证都设置为 IUSR。
此外,php.ini 中的 safe_mode
设置为 off
。
这里还有什么我需要检查的吗? cmd.exe 是否需要明确的 read/execute IUSR 权限?
事实证明,无论出于何种原因,IUSR 都是问题所在。我不能确切地知道为什么,但是将受影响网站的匿名身份验证更改为使用它工作的另一个用户。所以毕竟是权限相关的。