shell脚本在控制台上工作,但不是从php页面

I have a problem, I need to launch a .sh script from a web page, just does not go, starting from the terminal the script works and does what it has to do, but from the web no, but in the ' Apache2 error.log does not make any mistakes, I do not understand what it can be ..

HTML:

    <tr>
        <td>JTS</td>
        <td>
            <form action="JTSstart.php">
            <input type="submit" value="START">
            </form>
        </td>
                <td>
            <form action="JTSres.php">
            <input type="submit" value="RESTART">
            </form>
        </td>
                <td>
            <form action="JTSstop.php">
            <input type="submit" value="STOP">
            </form>
        </td>
    </tr>

PHP:

<?php
echo exec('bash JTSstop.sh');
sleep(5);
header("Location: 5ondimba.html");
?>

SH:

#!/bin/bash
cd  /home/otaku/JTS3ServerMod_HostingEdition
./jts3servermod_startscript.sh stop

What I have tried / tested: 1) The exec command, such as shell_exec, is not disabled in the php setup. 2) The files were converted with dos2unix. 3) bash -x on the script and does not report any kind of error (in fact, from console works).

what could it be?? how can i make it work? Thanks so much!

</div>

I see a few problems:

1) Get rid of echo. At best, it will display output of the command (if there is any), but if that happens it will cause your subsequent header() to fail - header() must be called before any output is generated.

2) PATHs are not the same in PHP as in your SHELL on the console. Don't assume bash or JTSstop.sh are in PHP's PATH, or in PHP's current working directory. Better to always fully specify paths.

3) Your script already includes #!/bin/bash, no need to call it with bash again.

PHP:

<?php
exec('/full/path/to/JTSstop.sh');
sleep(5);
header("Location: 5ondimba.html");
?>

But why not keep things simple and get rid of JTSstop.sh all together?

<?php
exec('cd /home/otaku/JTS3ServerMod_HostingEdition; ./jts3servermod_startscript.sh stop');
sleep(5);
header("Location: 5ondimba.html");
?>

If you're still having problems, you can see the results of the exec by specifying a 2nd parameter, as described in the docs.

<?php
exec('cd /home/otaku/JTS3ServerMod_HostingEdition; ./jts3servermod_startscript.sh stop', $output);
print_r($output);