2016-05-04 258 views
1

我能够通过命令行终端通过php执行shell脚本。但是当我通过浏览器单击HTML按钮时,我无法使用php执行相同的脚本(.sh)。无法在php中执行shell脚本

以下是我的PHP脚本(wettyload.php) -

<?php 
    shell_exec('/var/www/html/wettyload.sh'); 
?> 

以下是我的shell脚本(wettyload.sh) -

#!/bin/bash 
cd /root/wetty 
node app.js -p 8080 

以下是我的HTML代码(url.html) -

<html> 
    <body> 
     <form name="form2" method="post" action="http://127.0.0.1/wettyload.php"> 
      <input type="submit" id="url" name="url" value="Connect terminal"> 
     </form> 
    </body> 
</html> 
+4

你什么错误?也许你的网络服务器没有root权限? – colburton

+1

你的shell脚本将在默认的web用户下执行。确保用户具有执行权限。 – Webomatik

回答

0

使用

<?php 
    shell_exec('sh /var/www/html/wettyload.sh'); 
?> 

更新:

你之前还没有提到/root/wetty,你两个选择:

  1. 移动wetty目录到web服务器用户执行的位置权限。
  2. 设置的/root/wetty的权限,允许Web服务器用户执行(不安全)

注: 确保您已经execute权限wettyload.sh

+0

你认为web用户对'/ root'有任何权限? – AbraCadaver

+0

@AbraCadaver OP在更新了问题的同时,之前没有提及根... –