Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restarting Apache from PHP

Status
Not open for further replies.

Dustman

Programmer
May 7, 2001
320
US
Yes, I know its not safe but does anybody know of a way to restart apache from a php script on a linux box? This is for internal use only so I don't need all the warnings of security.. I know what i'm doing and the risk is poses.

I've been trying `service httpd restart` but apache doesn't have permission to do that. I can't pass a password to sudo to change to root (or at least i haven't seen a way to do it).. anybody got any ideas?

-Dustin
Rom 8:28
 
Set up your sudoers file so that the user as which Apache runs has permission to restart the service. If you give Apache's user access to the [tt]apachectl[/tt] command, you can probably set it up as a passwordless sudo session.

I have no idea whether a script within the server can actually restart the server. After all, the restart requires first a shutdown, which will end the session which ran the restart command. So, the server might not restart. If it doesn't, you might want to use your server's [tt]at[/tt] command to schedule the restart.



Want the best answers? Ask the best questions! TANSTAAFL!
 
While still unsafe, you could also run a standalone cron job with the necessary privileges to restart apache. Program that job to look for the presence of a file or a record in a MySQL table (which you can safely place without compromising the privileges used by PHP).

Then, when your flag/trigger (placed by PHP) is found, the standalone script (run every minute?) would take the necessary steps.

It's a separation of duty, but you are subject to cron'd cycles/schedule/uptime. Normally this is not a problem.

---

Another, approach might be to rig up logwatch to or some system monitor to respond with the restart based upon information passed to the monitor by PHP... this is getting a little more esoteric though.

I really don't prefer to compromise the security model for the web server if it can at all be helped.



D.E.R. Management - IT Project Management Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top