How can I have a PHP script run a shell script as root?

前端 未结 7 1191
野的像风
野的像风 2021-01-15 03:54

Running Fedora 9/10, Apache 2, PHP 5...

Can I run a shell script as root, from a PHP script using exec()?

Do I just give Apache root priveleges, and then add

7条回答
  •  隐瞒了意图╮
    2021-01-15 04:23

    You don't want to give Apache root.

    There's another solution to your problem. The problem is that Apache cannot kill the process because it is owned by root. What you can do is change the owner to 'www-data' which is what Apache is identified as.

    If the process is a service and starts up on boot you can add the

    sudo -u www-data 
    

    so that www-data would be the owner of that process and hence running the shut-down script would work.

提交回复
热议问题