![shell_exec で bash スクリプトを開始できません](https://rvso.com/image/1415046/shell_exec%20%E3%81%A7%20bash%20%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%E3%82%92%E9%96%8B%E5%A7%8B%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%9B%E3%82%93.png)
ここ数日、私はグーグルで検索して PHP スクリプトでこの問題を解決しようとしてきましたが、PHP スクリプトで Bash スクリプトを起動する際に私が見逃している問題を誰かが理解してくれることを願っています。
これが私の PHP です:
//kickoff the yapeal script
echo "Starting yapeal.sh<br>";
echo "Current working directory: ";
echo getcwd() . "\n";
shell_exec('./yapeal.sh');
echo "<br>yapeal.sh ran, I hope.<br>";
こちらがyapeal.shです
#!/bin/bash
cd /var/www/tools/applications
php -f /var/www/lib/yapeal/yapeal.php
sleep 5s
echo "`date -u` Yapeal kicked off, working" > bashoutput.log 2>&1
ファイルの権限は次のとおりです:
-rwxrwxrwx 1 www-data www-data 4640 Jul 10 07:20 index.php
-rwxrwxrwx 1 www-data www-data 2845 Jul 10 07:33 working.php
-rwxrwxrwx 1 www-data www-data 232 Jul 10 07:17 yapeal.sh
Web ブラウザで出力として得られるものは次のとおりです。
Starting yapeal.sh
Current working directory: /var/www/tools/applications
yapeal.sh ran, I hope.
bashoutput.log ファイルには出力がありません。
php.ini を確認しましたが、disable_functions セクションに exec または shell_exec への参照はありません。
答え1
私は自分の問題を自分で解決しました。
PHP コードを次のように変更しました:
$output = shell_exec('./yapeal.sh');
echo $output;