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

前端 未结 7 1196
野的像风
野的像风 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:12

    1. Don't run Apache as root. Apache has been designed to cope very well with starting as root and then dropping its privileges just as soon as it can

    2. Don't use sudo within your script either - it'll be too easy to end up with sudo misconfigured such that any script running on your server gets to run any program it likes with root privileges

    3. Look at making your own program run "setuid", so that it gets root privileges, but then drops them (just like Apache does) when it doesn't need them any more

    4. Make sure your "setuid" executable can't be run by anybody who isn't supposed to be able to run it.

提交回复
热议问题