无法在php中执行shell脚本


Not able to execute shell script in php

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

以下是我的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>

使用

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

更新:

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

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

注意:确保您对wettyload.sh 具有execute权限