我目前正在尝试从 php 脚本运行 wp cli命令。对于那些不熟悉WP-CLI的人来说,它是一个很酷的 Wordpress 命令行界面。以下是我的以下脚本:
<?php
// lets create a basic test
$cmd = '/usr/local/bin/wp core download';
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "path-to-error-log/error-output.txt", "a") // stderr is a file to write to
);
$process = proc_open($cmd, $descriptorspec, $pipes);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
$output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo $output;
}
?>
在里面error-output.txt
我收到以下错误:
sh: /usr/local/bin/wp: Permission denied
据我所知,这是一个权限问题,其中apache
(执行我的 php 脚本的当前用户)由于某种原因无法执行wp
bin 文件。
出于好奇,我做了以下事情:
- 更改了我要运行的命令,该命令
wp --info
输出有关 wp-cli 的信息并且不需要写入另一个目录,我认为这可能是一个问题,但我被证明是错误的,因为我仍然得到permission denied
错误。 - 我试图将
wp
垃圾箱移到usr/bin
。这里也没有效果。 - 无奈之下,我什至尝试给
wp
777 权限,apache
但仍然无法执行。
我意识到这更多是服务器设置/权限问题(可能),但我觉得这将是最好的提问地点。