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
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:Edit root's crontab with
incrontab -e
:Start it:
and create a
.conf
file in/etc/httpd/conf.d
and take a look at/var/log/cron
to see what happens.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: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.
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.