I'm working on a webpage, which after certain events, needs to restart the apache server that it's running on to update some files. I tried adding www-data to the sudoers file:
www-data ALL=(ALL) NOPASSWD: /etc/init.d/apache2 start, /etc/init.d/apache2 stop, /etc/init.d/apache2 restart, /sbin/services apache2 restart
but when I try restarting apache, I get the following:
sudo -u www-data /etc/init.d/apache2 restart
Restarting web server apache2 (13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
When looking online, I found that people seemed to be against allowing www-data to restart apache and I couldn't find anything suggesting how I would do it if I wanted to ignore the warnings for this particular case. If it isn't possible, what would be the easiest alternative way to have a webpage restart apache? I am going under the assumption that the site is private and secure and will not be used by malicious individuals, and I think it's a fair one given the circumstances I am under. Thanks for your time
The init-scripts can/should only be run as root (at least on my standard-Debian this is the case).
The apache-process (and the ones of the other services) will call setuid (or one of its friends) to change the actual user of the process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With