I recently upgraded my Mac’s OS from Lion to Lion Server, which changes how the httpd.conf settings are read when Apache is started. In particular, environment variables like WEBSHARING_ON and MACOSXSERVER are set by the Server.app process, so that extra modules and files are read in when Apache is started.
So now, to restart the Apache server with all the proper settings and modules loaded, I have to use the command:-
sudo serveradmin stop web && sudo serveradmin start web
Previously, I would run:-
sudo apachectl -S
sudo apachectl graceful
I prefer the latter method by far. For one thing, the command returns much quicker, and I also imagine that the apache / httpd server process doesn’t completely terminate, just the settings are reloaded.
So, is there a way to gracefully restart Apache in Lion Server?
The quick answer is no.
The ‘apachectl’ program is actually just a shell script, so (after realising this) it’s easy to see what it’s doing, and why it’s not doing what I expected.
When restarting Apache (gracefully or otherwise) on a Mac, the relevant launchctl job is just unloaded and reloaded, which I imagine is not as per the official Apache description of a graceful restart:
The reason
apachectl -Sdoesn’t show the configured virtual servers is because this command is not run by launchctl, and so the environment variables set in /System/Library/LaunchDaemons/org.apache.httpd.plist are not loaded.So,
apachectl graceful,apachectl restartand others do load the proper variables, and therefore read the config files properly, but not all commands do by default.To overcome this, I’ve manually edited /usr/sbin/apachectl, as below. All I did was add “-D MACOSXSERVER -D WEBSERVICE_ON” where appropriate.