Off course you’ll want to have Apache started automatically, just like the built in Apache would do. To do this we’ll need to write our own Startup item.

Open the Terminal and execute the following commands:

cd /Library/StartupItems
sudo mkdir Apache2

Then use your favourite editor (I like VI, but others like pico, it doesn’t matter) to create the following files into your newly created directory. Make sure you create them using sudo, so in the case of using VI the command would be: ‘sudo vi Apache2

The first file is called ‘Apache2′ and this is what it’s content should look like:

# Apache 2 Web Server startup item
. /etc/rc.common
StartService ()
  if [ "${WEBSERVER:=-NO-}" = "-YES-" ]; then
   echo “Please disable Personal Web Sharing and restart.”
   if [ "${APACHE2:=-NO-}" = "-YES-" ]; then
     echo “Starting Apache 2 Web Server”
     $APACHECTL start
StopService ()
  echo “Stopping Apache 2 Web Server”
RestartService ()
  if [ "${WEBSERVER:=-NO-}" = "-YES-" ]; then
   ConsoleMessage “Please disable Personal Web Sharing and restart.”
   echo “Restarting Apache 2 Web Server.”
   $APACHECTL restart
RunService “$1″

This first file has the start, stop and restart commands which will be called after a reboot. Use:

sudo chmod +x /Library/StartupItems/Apache2/Apache2

to make the script executable.

You could test this script yourself after you created the next file using the command to start Apache2:

sudo /Library/StartupItems/Apache2/Apache2 start

to stop Apache2 call:

sudo /Library/StartupItems/Apache2/Apache2 stop

and to just restart after a configuration change:

sudo /Library/StartupItems/Apache2/Apache2 restart

The second file is called ‘StartupParameters.plist’ and this is what it’s content should look like:

  Description = “Apache 2 Web Server”;
  Provides = (“Apache2″);
  Requires = (“DirectoryServices”);
  Uses = (“Disks”, “NFS”, “Network Time”);
  OrderPreference = “None”;

This file determines in which order Apache2 should start in relation to other programs that are started on your Mac. Apache for instance requires a running DirectoryService (or DNS) and it will wait for it t ostart before it starts itself. We can have other programs wait for Apache to start by putting in their StartupParameter file ‘Requires = (“Apache2″);’

The last thing you’ll need to do is to add the line:


to the file ‘/etc/hostconfig‘. This file is used to control the start of all the startup items on your machine.

Note: If you have the firewall running on your server (which by itself is a good idea) the ports for the webserver are closed because you stopped the Apache1 program in the Sharing Preference pane. You can open up those ports again by going into the Sharing preference pane and click on the Firewall tab. Create a new setting and make it look like:

WWW Firewall settings

Click “OK” and everything should be running as intended.

Next step: Installing PHP