#1  
Old 14th February 2007, 20:03
BlackGhost BlackGhost is offline
Junior Member
 
Join Date: Feb 2007
Location: Belgium, Zelzate
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Red face restart apache via php

Hello,

For the moment I'm setting up a configuration with apache as loadbalancer for jboss in cluster using the ajp13 with the mod_jk. Each jboss-instance runs on a seperate IP. So I've created virtual hosts for each IP on port 80 and 443. Now I want to setup a virtual host on the main IP on port 8443 where I can create a little control panel to automaticly generate vhost files and JBoss instances. My goal is to manipulate the server only via this contral panel. Therefor I need someting to restart apache gracefully in order to take count of the new created vhost-files.
I found the exec command in php and I to restart http I use /etc/init.d/htpd graceful

Now how can I put this together in a form with buttons. Do I have to do something for the user that runs the script?

Please help!!!
Reply With Quote
Sponsored Links
  #2  
Old 15th February 2007, 19:24
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,744 Times in 2,577 Posts
Default

Your control panel would have to run as root to be allowed to restart Apache. If your control panel runs under an Apache vhost (on port 8443), this won't work.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 16th February 2007, 00:41
sjau sjau is offline
Local Meanie
 
Join Date: Apr 2006
Location: Switzerland
Posts: 1,146
Thanks: 4
Thanked 55 Times in 51 Posts
Default

Code:
<?php

$submit = $_POST['submit'];

if($submit == "Restart") {

$message = '<p>Apache is being restarted</p>';
exec('/etc/init.d/httpd graceful');
$message .= '<p>Apache was restarted</p>';

}
echo '<html><head><title>Apache Restart</title></head><body>';
echo $message;
echo '<form action="" method="post">
<input type="submit" name="submit" value="Restart"></form>';

?>
Something like that should do it.

Save that file, chown it as root and make it 0777 (for testing)... if it works chmod it to rxrxrx
Reply With Quote
  #4  
Old 16th February 2007, 08:56
martinfst martinfst is offline
Senior Member
 
Join Date: Dec 2006
Location: Hilversum, The Netherlands
Posts: 880
Thanks: 1
Thanked 18 Times in 17 Posts
Send a message via MSN to martinfst Send a message via Skype™ to martinfst
Default

To execute a script as root, you should probably set the setuid bit:
Code:
chmod +s filename
However, setting the setuid bit for a script, which is activated by your webserver, is a security risk.

The alternative is to set a 'flag' somewhere (e.g. by creating a dummy file) and have a root cron script check if that file exists. If exists, restart apache and remove the flag file. Of course there are other mechanisms possible. You could have the crontab scan/run every minute. That way it will only take a minute before action is taken.
Reply With Quote
  #5  
Old 20th February 2007, 00:50
ctql ctql is offline
Junior Member
 
Join Date: Aug 2006
Posts: 23
Thanks: 1
Thanked 3 Times in 2 Posts
Default

The sticky bit didn't work for me when I needed this and I found this false bug explaining why: http://bugs.php.net/bug.php?id=22890&edit=1

Instead, this work around helped me:
http://adamyoung.net/Reload-httpd-via-PHP

I haven't looked at how ISPConfig does it yet although I have been curious...
Reply With Quote
  #6  
Old 20th February 2007, 09:08
martinfst martinfst is offline
Senior Member
 
Join Date: Dec 2006
Location: Hilversum, The Netherlands
Posts: 880
Thanks: 1
Thanked 18 Times in 17 Posts
Send a message via MSN to martinfst Send a message via Skype™ to martinfst
Default

Sorry, I wasn't complete. The workaround you found is a correct/complete solution. However, keep in mind there's still a security risk. Make sure you sanity / check every input string in your PHP sripts that calls this suid executable.
Reply With Quote
  #7  
Old 21st February 2007, 22:48
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,744 Times in 2,577 Posts
 
Default

Quote:
Originally Posted by ctql
I haven't looked at how ISPConfig does it yet although I have been curious...
There is a background daemon running as root, /root/ispconfig/sv/ispconfig_wconf, which checks every 10 seconds if the file /home/admispconfig/.run exists. If it exists, the ispconfig_wconf process starts the update process (as root).
The /home/admispconfig/.run can be created by the Apache user.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Freebsd 6.1 support misterm Installation/Configuration 10 9th April 2009 09:29
Slightly Confused (DNS & Server Help) JohnnyBGoode Installation/Configuration 26 14th August 2007 09:54
VirtualHosts marra87 General 9 12th September 2006 04:09
"unknown filter" growing apache log. wwparrish Installation/Configuration 6 1st September 2006 18:40
Downgrade php5 to php4.4.2 llizards Installation/Configuration 4 13th March 2006 23:58


All times are GMT +2. The time now is 20:42.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.