I have a CentOS 5.7 linux server and use php5.3.x.
On a pfSense system, you can restart services-that required root permissions using a php web page.
I'm trying to do something similar, I have written some php code to execute shell commands. For example, to restart the sshd service:
<?php
exec('/sbin/service sshd restart');
?>
and I tried to execute that command via exec function, but it needs root permission, but we have a apache user authority.
I have come across a few solutions:
- "run apache with root user" really unsafe. I do not want to do that.
- "apache ALL=NOPASSWD:/sbin/service to /etc/sudoers" I tried but and still have a problem.
Any other solutions? Thanks for answers.
now.. it's interesting. i tried @refp post and it worked my local ubuntu server. But when i tried same at my cenOS vps server. It's not working.and that is apache's error log "rm: cannot remove `/var/lock/subsys/vsftpd': Permission denied"
sudoers
solution? What problem did you have? Did you addsudo
in theexec()
command? Or anything worthwhile in theerror.log
, syslog, or/var/log/auth.log
for that matter? – marioALL
as a host spec?localhost
should be enough!). Also, if yoursudoers
has it, removeDefaults require_tty
, since Apache won't run with a tty attached to it. – fge