Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to restart apache with serveradmin environment variables set?

Hi,


With any Unix machine, one can run at the command line:-


apachectl -S


This will show all virtual servers configured in Apache, and will break if there are any obvious problems in the httpd .conf files. It's very handy for testing a new configuration before restarting the server.


With Mac OS X Server though, this doesn't work properly. Sure, I can run that command and see a virtual server or two, but with the introduction of the server Apache wrappers, the command line tools read a very different configuration than the `serveradmin` tool does.

e.g. Wrappers like:-

<IfDefine MACOSXSERVER>
    ....
</IfDefine>

or

<IfDefine WEBSERVICE_ON>
    Include /etc/apache2/sites/*.conf
</IfDefine>


There's loads of these, and they mean that I can't use any of my favourite apache command line tools.

A really critical command that I'm pretty sure doesn't work with these wrappers is:-


sudo apachectl graceful



So, how can I use apachectl under Mac OS X server? There's a couple of quite large plist files in the /etc/apache2 directory, but I don't know how to read plist settings into the environment before executing a program. The Developer documentation seems directed towards ObjC developers, which I am not.

Any help much appreciated.

Cheers,

Alex


ps. Running `sudo serveradmin stop web && sudo serveradmin start web` really ***** compared to `apachectl graceful`; it's painfully slow and doesn't provide a way to test a custom configuration before attempting to restart.

Mac Pro mid-2010, Mac OS X (10.6.4)

Posted on May 21, 2012 7:26 AM

Reply
2 replies

Jun 25, 2012 1:44 PM in response to Strontium90

Thanks for the suggestion. It doesn't make a difference though, because `configtest` still doesn't load the environment variables stored in the relevant plist file.

I since noticed, soon after initially posting this question, that apachectl is just a shell script, so it's quite easy to see what it's doing, and also, to edit...

For instance, the restart / graceful command is defined in the script as:-

restart|graceful)

run_launchctl unload -w $LAUNCHD_JOB 2> /dev/null

run_launchctl load -w $LAUNCHD_JOB

ERROR=$?


As these use launchctl, the environment variables in the plist file are used, so that's all good. However, with configtest and other commands, the httpd executable is called directly, without first loading the plist variables. i.e.

configtest)

$HTTPD -t

ERROR=$?


Manually setting the environment variables doesn't help, but looking at `apachectl -h`, one can see that variables can be passed by adding `-D ...` command line arguments.


So, my solution is to manually add the necessary keyword arguments to each ${HTTPD} call in apachectl.


The bottom of my /usr/sbin/apachectl is now as follows:-


configtest)

$HTTPD -t -D MACOSXSERVER -D WEBSERVICE_ON

ERROR=$?

;;

status|fullstatus)

echo Go to $STATUSURL in the web browser of your choice.

echo Note that mod_status must be enabled for this to work.

;;

*)

$HTTPD $ARGV -D MACOSXSERVER -D WEBSERVICE_ON

ERROR=$?

esac


Hope this might come in handy for anyone else in the same predicament...

How to restart apache with serveradmin environment variables set?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.