|
Posted by theGerm on 03/29/07 19:01
On Mar 29, 1:25 pm, Schraalhans Keukenmeester <bitbuc...@invalid.spam>
wrote:
> theGerm wrote:
> > On Mar 29, 11:34 am, Toby A Inkster <usenet200...@tobyinkster.co.uk>
> > wrote:
> >> 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!
>
> > I have this
>
> > <?php system("sudo /etc/init.d/squid reload 2>&1"); ?>
>
> > on that page I just see text - Password:
>
> You can configure sudo's behaviour per command/user. As it is, it seems
> like yours is set up so the sudo-ing user has to supply their own
> password first before sudo will exec the command (squid int his case,
> which prolly has root exec rights only, maybe group wheel as well.)
>
> in /etc/sudoers you can set the desired behaviour for squid and/or the
> user that 'runs' apache/php. Normally apache is started as root, but in
> httpd.conf the user that holds the apache processes is specified. See ps
> aux for details on your apache user.
>
> see man sudo, man sudoers for details on how to set the proper
> behaviour. Or check google for mor elaborate examples/walkthroughs.
>
> Hth
>
> Sh.- Hide quoted text -
>
> - Show quoted text -
sudo got it now I added this line in my sudo file
apache ALL= NOPASSWD: /etc/init.d/squid
Navigation:
[Reply to this message]
|