[英]running shell script with html button
我正在使用 3 個腳本,目的是用 HTML 按鈕命令 shell 腳本。
我的 shell 腳本只是簡單地啟動 'nautilus',一個 Linux 文件瀏覽器:
#!/bin/bash
nautilus
exit 0
PHP 腳本調用 shell 腳本如下:
<?php
exec('./test.sh');
?>
至少,我的 HTML 頁面是這樣的:
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<input type="button" onclick="openApp.sh" value="Open Script">
</body>
</html>
3個腳本位於
/var/www/html
擁有以下權利:
sudo chown www-data:www-data /var/www/
我做錯了什么,因為它不起作用! 但是當我啟動這個命令時:
cd /var/www/html
php script.php
它正確調用了啟動 nautilus 的 shell 腳本。
你知道什么是錯的嗎?
謝謝
當您從 PHP 運行該命令時,它會在純文本 shell 中執行,因此不會創建可見的 GUI。 如果通過 apache/nginx 運行,PHP 通常以名為 www-data 的用戶身份運行。
您需要確定運行圖形顯示的用戶的用戶名、顯示編號和授權cookie。
有關更多詳細信息,請參閱此對話https://unix.stackexchange.com/questions/1596/can-i-launch-a-graphical-program-on-another-users-desktop-as-root
確定顯示后。 你的 test.sh 腳本看起來像這樣
DISPLAY=:0
XAUTHORIZATION=~/.Xauthority
su username -c "nautilus" # replace username with username of your desktop/graphical user
還要注意不要讓外部用戶使用 PHP 在服務器上運行命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.