Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restarting apache as www-data using perl

Tags:

unix

perl

apache2

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

like image 223
Ahmed Avatar asked Nov 13 '22 18:11

Ahmed


1 Answers

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.

like image 61
Patrick B. Avatar answered Dec 06 '22 03:12

Patrick B.