从PHP脚本运行WP-CLI
我目前正在尝试从php脚本运行wp cli。对于那些不熟悉它的人来说,Wordpress有一个很酷的命令行界面。以下是我的以下脚本:从PHP脚本运行WP-CLI,php,wordpress,permission-denied,proc-open,Php,Wordpress,Permission Denied,Proc Open,我目前正在尝试从php脚本运行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 fr
<?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:权限被拒绝
据我所知,这是一个权限问题,apache
(当前执行我的php脚本的用户)由于某种原因无法执行wp
bin文件
出于好奇,我做了以下工作:
将我要运行的命令更改为wp--info
,该命令输出有关wp cli的信息,并且不需要写入另一个目录。我假设这可能是一个问题,但我被证明是错误的,因为我仍然收到权限被拒绝的错误
我尝试将wp
bin移动到usr/bin
。这里也没有效果
出于绝望,我甚至尝试给予wp
777权限,而apache
仍然无法执行
我意识到这更多的是一个服务器设置/权限问题(可能),但我觉得这将是最好的提问地点。您(几乎)不需要chmod 777
,就可以使用chmod 555
,使文件可读且可执行;(这对所有UNIX-y系统都是一样的)从这一点来看,我认为这个问题不再是wp
bin上的权限问题,因为我刚才尝试了555,但收到了相同的错误,因为777也不起作用。是的,这只是一个一般性的评论。好的,谢谢:)我会记住这一点。你试过:*从你的PHP脚本执行其他系统命令吗?*是否将WP-CLI Phar文件移动到与脚本相同的目录,并在那里执行?也可能是其中之一:**