How to run from PHP a bash script under root user

前端 未结 5 1480
天涯浪人
天涯浪人 2020-12-09 18:02

How to run from PHP a bash script under root user (with all permissions) and not nobody user - php default user?

thats my output af

5条回答
  •  轮回少年
    2020-12-09 18:43

    You can use sudo:

    exec("sudo /your/script");
    

    You should allow executing your script without password prompt. Run sudo visudo in console and add the following string to the end:

    nobody ALL = NOPASSWD: /your/script
    

    You must set up file mode properly to ensure that no one can modify this script and put dangerous contents into it (in root console):

    chown root:root /your/script
    chmod 755 /your/script
    

提交回复
热议问题