开发者

Restarting apache as www-data using perl

开发者 https://www.devze.com 2023-03-28 07:47 出处:网络
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:

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.


root should restart the webserver:

sudo /etc/init.d/apache2 restart

This will make apache run under the www-data user.

you don't need to add www-data to the sudoers file unless you want to allow the www-data user to restart the server - but typically you should not log in under the www-data account, it's a system account.

0

精彩评论

暂无评论...
验证码 换一张
取 消