Page 1 of 1

Restart service via PHP

Posted: Tue Aug 25, 2009 5:47 am
by lieb39
Hello everyone,

Been bashing my head for the past two days on this... I'm nowhere near experienced to figure out how to do this from scratch so I've been searching for the past two days for this..

How can I restart a service (specially the squid service) via a PHP webpage? I know there are a lot of complications with permissions and commands - I'm not too fussed on the permission/security front, as this is a private project and won't be entering the real world :)

I've tried exec(service squid restart) but the error goes down to permissions there..

Any ideas?

Thanks!

lieb39

Re: Restart service via PHP

Posted: Fri Sep 11, 2009 3:51 am
by dude81
add the webserver user group to root group and execute the code

Re: Restart service via PHP

Posted: Fri Sep 11, 2009 4:23 am
by VladSun
You'd better use sudo instead of changing any permissions (or membership).

Re: Restart service via PHP

Posted: Mon Oct 26, 2009 4:56 pm
by agentz
what do you guys thinking about SSH ?
will it work (connect via PHP to SSH and send the command) ?

Re: Restart service via PHP

Posted: Mon Oct 26, 2009 5:21 pm
by Eran
Why would you need to connect to anything? PHP already runs on the server. You just need the proper permissions / credentials.

Re: Restart service via PHP

Posted: Wed Oct 28, 2009 1:50 am
by iloveoct2
visudo and add webuser.

sudo allows a permitted user to execute a command as the superuser or another user, as specified in the
sudoers file. The real and effective uid and gid are set to match those of the target user as specified
in the passwd file (the group vector is also initialized when the target user is not root). By default,
sudo requires that users authenticate themselves with a password (NOTE: by default this is the user’s
password, not the root password). Once a user has been authenticated, a timestamp is updated and the
user may then use sudo without a password for a short period of time (5 minutes unless overridden in
sudoers).

man visudo
man sudo