简体   繁体   中英

Not able to execute shell script in php

I am able to execute the shell script through php via command line terminal. But I am not able to execute the same script(.sh) using php when clicked on HTML button through browser.

Following is my php script(wettyload.php)-

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

Following is my shell script(wettyload.sh)-

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

Following is my html code(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>

Use

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

Update:

You didn't mention /root/wetty before, you've a couple of options:

  1. Move the wetty dir to a location where the webserver user has execute permissions.
  2. Set the permission of /root/wetty to allow the webserver user to execute (unsafe)

Note: Make sure you've execute permissions to wettyload.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM