Run a script as root from apache

Posted by Lord Loh. on Server Fault See other posts from Server Fault or by Lord Loh.
Published on 2012-04-09T18:20:02Z Indexed on 2012/04/12 5:32 UTC
Read the original article Hit count: 130

Filed under:
|
|
|
|

I would like to update my hosts file and restart dnsmasq from a web interface (php/apache2). I tried playing around with suid bits (the demonstaration). I have both apache and dnsmasq running on an EC2 instance.

I understand that Linux ignores the setuid bit on text scripts, but works on binary files. (Have I got something wrong?). I added exec("whoami"); to the example C program in Wikipedia. Although the effective UID of the C program is 0, whoami does not return root :-(

I would thoroughly like to avoid

echo password | sudo service dnsmasq restart

or adding apache to the sudoers without password! Is there a way out? How does webmin do such things?

© Server Fault or respective owner

Related posts about apache2

Related posts about sudo