現在、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
たが、それでも実行できませんでした。
これはサーバーのセットアップ/許可の問題であると認識していますが (おそらく)、これが質問するのに最適な場所であると感じました.