I'm trying to access a deb system service with PHP shell_exec
and I just can't get it working.
This is the command I am trying to run from a php script :
shell_exec('sudo service icecast2 stop');
But it's not working for two reasons..
1) I'm not sure if I'm granting the correct user permissions in /etc/sudoers
?
%www-data ALL=NOPASSWD: /sbin/???????
2) ??????? = I'm not sure where to point to in the /sbin to allow access to system services? I've tried a variety of things but as I'm not sure which part I'm getting wrong (possibly both) I haven't been able to get anything to work.
Any help appreciated ;)
On my Debian systems service
is in /usr/sbin
, not in /sbin
. So it should be:
%www-data ALL=NOPASSWD: /usr/sbin/service
You should also use the full path in the shell_exec()
command, as /usr/sbin
might not be in the webserver's $PATH
.
shell_exec('sudo /usr/sbin/service icecast2 stop');