Executing a shell script from a PHP script

后端 未结 4 804
时光取名叫无心
时光取名叫无心 2020-11-27 05:55

I want to execute a Bash script present on the system from a PHP script. I have two scripts present on the system. One of them is a PHP script called client.php

4条回答
  •  日久生厌
    2020-11-27 06:36

    I would have a directory somewhere called scripts under the WWW folder so that it's not reachable from the web but is reachable by PHP.

    e.g. /var/www/scripts/testscript

    Make sure the user/group for your testscript is the same as your webfiles. For instance if your client.php is owned by apache:apache, change the bash script to the same user/group using chown. You can find out what your client.php and web files are owned by doing ls -al.

    Then run

    &1");
          print_r($message);
        ?>  
    

    EDIT:

    If you really want to run a file as root from a webserver you can try this binary wrapper below. Check out this solution for the same thing you want to do.

    Execute root commands via PHP

提交回复
热议问题