Making a Custom Apache Install Start at Boot on Mac OS X
If you're new here, you may want to subscribe to my RSS feed or follow me on Twitter. Thanks for visiting!
A Bit Of Background
I do all of my web-development on a Mac OS X machine (a MacBook Pro, to be exact) using a local install of Apache, PHP and MySQL. I’m using a custom built Apache 2 install and configuration (for various reasons) so the default Web Sharing control panel does not control the starting and stopping of my webserver. In general, my setup works really well and has led to a really integrated workflow that I can use and develop with even while offline. One thing that had always frustrated me about my custom setup though, is that after a restart, apache had to be manually started before I could get back to work. This is one of those little things that can be annoying, but not really annoying enough to do anything about. Well, I finally decided to fix it.
Mac OS X has a system startup program called launchd which allows us to start the apache webserver automatically on each system boot. You can read more about launchd at the official apple page.
Making Our Own launchd File
To create the launchd plist file, I used Lingon which is an open source graphical front-end for creating these types of files (version 2.0.2 as of this writing). You can use this article as a reference for creating your own, or simply download the apache2 launchd plist file, unzip it, and place the file into /Library/LaunchDaemons/. This file assumes that you have apache2 installed in /usr/local/apache2/.
Once Lingon is launched, you’ll be presented with a window that’ll show you an overview of all of your currently installed launchd files. Click the “new” button to create a new file. You’ll want a Daemon file since apache needs to run at startup and as root:

Once you’ve got a new file ready for editing, fill out the “Name” field. I’ll be using “com.mirthlab.launchd.apache2”:

Next, fill out the “What” field. This will be the command we want to run at startup and I’ll be using “/usr/local/apache2/bin/apachectl start” but this may differ if you have Apache installed in a different location:

And finally, fill out the “When” field. For Apache, I checked the box that says “Run it when it is loaded by the system (at startup or login)”:

Wrapping It All Up
Click “Save” and enter your password when prompted. This is a root level launchd daemon which is why Lingon needs your password.
Restart and you should have Apache ready to go!
NOTE: If you simply downloaded the plist file, you’ll probably have to change this file’s ownership as files in /Library/LaunchDaemons/ must be owned by root.
To change the file’s owner to root, in the terminal, type:
sudo chown root:wheel /Library/LaunchDaemons/com.mirthlab.launchd.apache2.plist
… all on one line.
You can also see this macosxhints.com hint for a tip on using the Sharing Control Panel to start and stop your custom Apache install.
About this entry
You’re currently reading “Making a Custom Apache Install Start at Boot on Mac OS X,” an entry on MirthLab
- Published:
- Thursday, December 6th, 2007 at 10:55 am
- Author:
- Mark Quezada
- Category:
- Web Development

No comments
Jump to comment form | comments rss | trackback uri