Oct 23
Giving PHP exec() some privilege
My problem is I and working on a web interface which runs some limit shell command. Some of these normally require root access… And I don’t want to do something silly like force apache to run as root now do I?
Provided you have sudo installed (like most distro’s) the following is a good solution I came across!
Update your sudoer config (mines at /etc/sudoers) so your apache user can run the required command.For example:
Cmnd_Alias TOOLS=/usr/sbin/yourcommand,/usr/sbin/anotherone www-data ALL=NOPASSWD: TOOLS
Then in your PHP you would execute the command like so:
exec("/usr/bin/sudo /usr/sbin/yourcommand");
If anyone can suggest a better method I’d love to hear!!
