Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a LAMP server running on CentOS 5.5 64-bit and would like to reload my httpd service after making new subdomains.

I have 3 servers mounted onto my web server, and depending on what resources each mounted server has i create new user accounts and add them to the available server.

for instance when a user registers and needs 5gb of space then my PHP scripts searches through my mounted servers to see if they have an allocation slot open for a new user. if not then it moves to the next server and so on. So depending on the server they end up in i create a new conf files to reflect that server as their DocumentRoot

the issue is that i need to reload the httpd service manually after each subdomain is created for a particular user.

I am trying to find a way to have the httpd service reloaded as soon as a user registers.

currently i am trying this:

system("/bin/echo '/sbin/service httpd reload > /dev/null 2>&1' | /usr/bin/at now");

my httpd service is located at /etc/init.d/httpd

share|improve this question

3 Answers 3

up vote 3 down vote accepted

Execute commands requires root from PHP is not good idea. I would suggest you monitoring the /etc/httpd/conf.d folder and reload Apache whenever it changes. Take a look at incron.


Install it from rpmforge repository:

# yum -y install incron

Edit root's crontab with incrontab -e:

/etc/httpd/conf.d/ IN_CREATE,IN_DELETE,IN_MODIFY /etc/init.d/httpd reload

Start it:

# service incrond start
# chkconfig incrond on

and create a .conf file in /etc/httpd/conf.d and take a look at /var/log/cron to see what happens.

share|improve this answer
    
do you have any live examples on how to use incron? –  s2xi Aug 31 '11 at 8:50
    
Check out my above example (I've not tested). –  quanta Aug 31 '11 at 9:01
    
oh wow, easier than i thought! let me try –  s2xi Aug 31 '11 at 9:14
    
rpmforge repo. –  quanta Aug 31 '11 at 9:16
    
ok got it installed and added the example provided then loaded up incrontab /helix/cron_conf.txt the started the service. i did make a new conf file but when i check the logs it didn't log anythin –  s2xi Aug 31 '11 at 9:25

I would do this by having php create a directory somewhere in the filesystem and then have a cron script run as root that would check for the existence of the directory and restart the HTTP server if it exists and remove the directory. This way at least you are not giving the httpd user too much privilege.

share|improve this answer
    
hmmm, let me look into that. I thought of that at some point but i think i just got lazy with thinking of how i would approach that from a programming stand point. –  s2xi Aug 31 '11 at 8:32
1  
Lazy is the mother of security breach. –  Iain Aug 31 '11 at 8:35
    
i know, but still human nature to want to take shortcuts when you feel that end is in sight ;) –  s2xi Aug 31 '11 at 8:38

The PHP script could invoke "apachectl restart" via sudo (ie, sudo /usr/sbin/apachectl restart), and sudo could be configured to permit the user that runs httpd (and therefore, presumably, the PHP script) to run that command without password. This line of sudoers code would achieve that:

apache  ALL=(root) NOPASSWD: /usr/sbin/apachectl restart

Obviously, you will need to ensure that the user and path there are correct for your environment; mine are taken from a CentOS 5 system.

share|improve this answer
    
is that a bash command or something i would run system or exec functions with? –  s2xi Aug 31 '11 at 8:24
1  
Both; it is suitable for use as a bash command, and therefore also something you could invoke with the system() call. –  MadHatter Aug 31 '11 at 8:38
    
when you say apache is that the user or group your trying to run the command in? –  s2xi Aug 31 '11 at 8:46
    
The user. (filler text) –  MadHatter Aug 31 '11 at 8:47
    
when i run this in the terminal it returns -bash: syntax error near unexpected token (' –  s2xi Aug 31 '11 at 8:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.