I am using a cron job to reload my httpd service after a subdomain is created. I have the problem that when the reload happens the page that registers the user throws a server error.
I was wondering if I could go around this by having another cron task.
So my logic would be:
httpd reload after a .conf file is created then take the user back to the DocumentRoot of the main page.
So in usage it would be:
a user registers, then is automatically taken back to domain.com
"load a php page..."
Does that mean you are trying to invoke this via HTTP?
That's a bad idea to begin with - it means that you've potentially exposed functionality which could be accessed by someone not intended to have access to it.
So it's running with root privileges? That's a really bad idea.
From your description, you seem to be trying to provide a facility for users to create their own domains. It would be much more preferable to use a wildcard vhost definition, then use mod_rewrite to map the dynamically mapped path to a new directory.
But failing that the best way to do this would be to implement it as a setuid root script on the server (with authentication built-in as well as authentication on the web page) and call this from the web page.
....and if the process is started by a web request, then why use cron in the middle? Certainly you'll get privilege seperation if the cron job job is NOT accessing the php script via HTTP, but you're making things much harder than they need to be and introducing delays / load on the server you don't need.
Do a graceful restart on the apache, that will allow childs to finish the current request before reloading the config.
This is the wrong way to solve this problem.
The right way involves using some kind of software "router". I don't actually mean an IP router, I mean an URL rewriting type router.
So your application listens to anything on
*.domain.com
, and then hands it off to the right user's application instead of that tedious apache reloading nonsense.I did something similar in Nginx recently.
Basically, for any subdomain under domain.com, it gets mapped to
$DOCROOT/sites/$subdomain/index.html
As a result, to add a new subdomain, all I need to do is create a directory under sites/"subdomain", and it's instantly accessible.