You are here

Installing Apache 2 on Mac OS X 10.4 (Tiger)

Error message

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in drupal_strip_dangerous_protocols() (line 1458 of /home2/crephoto/public_html/techblog/includes/common.inc).

Apache 2 offers many improvements over Version 1.3 that comes with Mac OS X 10.4. That's probably why it comes with Mac OS X 10.5! For those of you who are just hankering for Apache 2 but not quite ready for the move to Leopard, here's how it's done. Roll up your sleeves, boys & girls...

Disable Apache 1.3

The first thing you have to to is disable the Apache 1.3 web server. In the "System Preferences" app, go to "Sharing", and turn off "Personal Web Sharing".

Download & Install

Download the latest stable release from http://httpd.apache.org using your preferred tools. For example:
$ wget http://apache.opensourceresources.org/httpd/httpd-2.0.63.tar.gz

extract tarball into a temporary location in your home directory (Desktop, whatever):
$ tar xvzf httpd-2.0.63.tar.gz

Compile the source & install:

$ cd httpd-2.0.63
$ ./configure --prefix=/usr/local/apache2
$ make
$ sudo make install

Launch at Startup

To enable the Apache 1.3 web server under Tiger, all you needed to do was turn on "Personal Web Sharing" under the System Preferences. That's not going to work anymore. In order for Apache 2 to launch automatically when you startup your machine, you have to create a StartupItem. Here's how.

First change to the StartupItems directory:
$ cd /Library/StartupItems

Create a new folder for the Apache2 StartupItem (this directory is owned by root, so you need to sudo):
$ sudo mkdir Apache2
$ cd Apache2

Next you'll be creating a couple of text files. The first is the startup shell script itself, the second is a plist file which defines some parameters for the startup script. Fire up your favorite text editor, and create a file called "Apache2" in the /Library/StartupItems/Apache2 directory.

$ sudo vi /Library/StartupItems/Apache2/Apache2

(Note that you don't need to include the full path if you followed the "cd" step above). Add the following content:

#!/bin/sh
# Apache 2 Web Server startup item
# http://diymacserver.com
#
 
APACHECTL="/usr/local/apache2/bin/apachectl"
 
. /etc/rc.common
StartService ()
{
  if [ "${WEBSERVER:=-NO-}" = "-YES-" ]; then
   echo "Please disable Personal Web Sharing and restart."
  else
   if [ "${APACHE2:=-NO-}" = "-YES-" ]; then
     echo "Starting Apache 2 Web Server"
     $APACHECTL start
   fi
  fi
}
 
StopService ()
{
  echo "Stopping Apache 2 Web Server"
  $APACHECTL stop
}
 
RestartService ()
{
  if [ "${WEBSERVER:=-NO-}" = "-YES-" ]; then
   ConsoleMessage "Please disable Personal Web Sharing and restart."
   StopService
  else
   echo "Restarting Apache 2 Web Server."
   $APACHECTL restart
  fi
}
 
RunService "$1"

This file has to be executable, so:
$ sudo chmod 755 /Library/StartupItems/Apache2/Apache2

Next you'll have to create a plist file called StartupParameters.plist. Add the following:

{
  Description = "Apache 2 Web Server";
  Provides = ("Apache2");
  Requires = ("DirectoryServices");
  Uses = ("Disks", "NFS", "Network Time");
  OrderPreference = "None";
}

Save this file as "/Library/StartupItems/Apache2/StartupParameters.plist". Now test your new script:
$ ./Apache2 start

If you still have Apache 1.3 running you will get an error. if you don't get any errors, try:
$ ps aux | grep httpd | grep -v grep

You should see several instances of the http daemon running. If not, check your system log:
$ grep Apache2 /var/log/system.log

And look any mention of syntax errors in either the Apache2 startup script or parameter list file. If everything has worked up to this point, reboot your machine to verify that Apache2 is loading at startup. You can use the same "ps" command to verify the httpd process is running.