無法使用 shell_exec 啟動 bash 腳本

無法使用 shell_exec 啟動 bash 腳本

幾天來我一直在谷歌搜尋並試圖用我的 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

以下是我在網頁瀏覽器中得到的輸出:

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;

相關內容