Posted by Toby A Inkster on 03/29/07 16:34
theGerm wrote:
> Is it possible for me to restart a service with PHP? I need to run
> this from a webpage
>
> /sbin/service squid reload
You can run that using PHP's system() function:
<?php system("/sbin/service squid reload"); ?>
However, normally "/sbin/service X" is just a shortcut to running
"/etc/init.d/X" and if you take a look at the permissions for the contents
of the "/etc/init.d/" directory, they'll mostly be only executable by
root. (And the web server doesn't run as root!)
So the initial reaction is to just change the permissions on
"/etc/init.d/squid" to allow non-root users to run it. That won't work
though.
What you'd need to do is use "sudo" to allow whatever user Apache runs
under (normally the user is called "httpd", "apache" or "nobody") to be
able to run "/etc/init.d/squid".
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
[Back to original message]
|