Off course you’ll want to have Apache started automatically, we will use the new launchd system in Leopard to accomplish this.
Create a file called ‘com.diymacserver.apache2.plist‘ in the directory ‘/System/Library/LaunchDaemons/‘. The content of the file should look like:
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.diymacserver.apache2</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/apache2/bin/apachectl</string>
<string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
To load and activate the .plist file and to make sure that it is started after a reboot you’ll need to load the plist file by using the command:
You can see if it loaded correctly by using the command:
This will show you all the active plist files.
You can see if everything went correctly by trying to start it using:
Next step: Installing PHP



1:06 am
When I tried to load the plist I received the following,
launchctl: opendir() failed to open the directory
nothing found to load
Any ideas?
5:13 am
I guess the error message speaks for it self, did you make an error in the path, did you use sudo, etc… It can’t open the file therefore something is wrong in your commandline.
2:19 am
I admit I’m not very versed in the Mac launchctl process. (I’m not sure I like it.)
Following these startup steps I can use launchctl to ‘load’ the plist — which starts the server. Using the ’start’ subcommand issues no errors. But I observe that the ’stop’ subcommand does not stop the server.
Is this because of the ’start’ command here in the plist? Is it required to ‘unload’ the plist to shutdown the server?
7:56 am
You are correct, the launchctl program is configured to keep the Apache server running. If you like to have more control you could use the ‘old’ method as described here: http://diymacserver.com/installing-apache/starting-apache-at-boot/
It will still work on Leopard but it will be fased out at some point in the future as indicated by Apple.
8:44 pm
sudo launchctl load /System/Library/LaunchDaemons/com.diymacserver.apache2.plist
launchctl: Dubious ownership on file (skipping): /System/Library/LaunchDaemons/com.diymacserver.apache2.plist
nothing found to load
I don’t like launchctl as it doesn’t like my save files!
10:08 pm
Your files should be owned by root! Make sure that is the case.
5:26 pm
The biggest concern I have with using launchd with apache2 as show is that the httpd processes are ran as root - not a separate account (e.g., www, web). Running apache as root is really a bad idea (read security risk).
Using the .plist username property does not appear to work as it does with my other services.
UserName
www
This is commonly done, just need to find a reference to how to do it with OSX.
5:32 pm
The username for the apache processes is defined in the httpd.conf using:
User _www
Group _www
If you are using Leopard then use “_www” on Tiger use “www”
5:41 pm
Thanks Richard is was under my nose the whole time.
6:05 pm
Is this *starting* apache as root or running apache as root? my phpinfo still says its running under WWW … should i be concerned and still modify my plist file again?
6:08 pm
Apache will eventually run as the user/group configured in your httpd.conf. The starting process will be started as root but apache will spawn the httpd deamons as the configured user and die off…