Restart service via PHP

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
lieb39
Forum Newbie
Posts: 1
Joined: Tue Aug 25, 2009 5:44 am

Restart service via PHP

Post 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
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Re: Restart service via PHP

Post by dude81 »

add the webserver user group to root group and execute the code
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Restart service via PHP

Post by VladSun »

You'd better use sudo instead of changing any permissions (or membership).
There are 10 types of people in this world, those who understand binary and those who don't
agentz
Forum Newbie
Posts: 4
Joined: Sat Sep 05, 2009 9:19 am

Re: Restart service via PHP

Post by agentz »

what do you guys thinking about SSH ?
will it work (connect via PHP to SSH and send the command) ?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Restart service via PHP

Post by Eran »

Why would you need to connect to anything? PHP already runs on the server. You just need the proper permissions / credentials.
iloveoct2
Forum Newbie
Posts: 2
Joined: Wed Oct 28, 2009 1:41 am

Re: Restart service via PHP

Post 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
Post Reply