Building and Installing Apache 2 and PHP 5.1.1 on Mac OS X 10.4.3 Tiger

By: James Pelow (jamesnp) Posted: 29-Nov-05, 07:49:40 Rated: General/Experienced

Alert!: Warning: This article/tutorial is more the 45 days old. As such the information contained within could be, by now, out of date. Please read all information to make sure that this article/tutorial will work with your current version of the Operating System


FYI Usual stuff… Full Developers’ Tool installation is required as well as up to date system. At this time it means 10.4.3 WITH ALL latest Security Updates.

For anyone that has been wishing to switch to Apache 2 on their Mac, this is the time to do it. PHP 5 has also recently been updated to 5.1.1 and this tutorial describes in detail, the best method to both build and install these programmes on your Mac.

Since Apple don’t include Apache 2 with OS X yet I have felt it better to keep Apache 2 in its own directory, and to keep PHP for Apache 2, etc. confined the that directory too.

Step 1: Downloading Apache 2----------The first step, as in any build like this, is to download the source and uncompress it. To do this we open the Terminal and enter the following commands. FYI: the % represents the Command Line Prompt and should not be entered

% curl -O
% gnutar -xzf httpd-2.0.55.tar.gz

Step 2: Building and Installing Apache 2----------I’ve decided to install to a new directory which we will make /apache2. It’s nice and convenient. To do this enter the following commands (sudo is required as the directory doesn’t already exist):

% cd httpd-2.0.55
% sudo ./configure \
% –prefix=/apache2 \
% –enable-module=most \
% –enable-shared=max
% sudo make
% sudo make install

Step 3: Building and Installing PHP----------Building and Installing PHP with Apache 2 is fairly simple. We want to install it into the same directory as Apache… just for sanity’s sake.

% curl -O
% gnutar -xzf php-5.1.1.tar.gz
% cd php-5.1.1
% sudo mkdir /apache2/php

Once all that’s done, we will configure and compile PHP.

% ./configure \
% –prefix=/apache2/php \
% –with-zlib \
% –with-xml \
% –with-gd \ (optional, requires jpeg + png)
% –with-jpeg-dir=/usr/local \ (optional)
% –with-png-dir=/usr/local \ (optional)
% –with-mysql=/usr/local/mysql \ (optional)
% –with-apxs2=/apache2/bin/apxs
% make
% sudo make install

The lines marked “Optional” are optional. lib jpeg and png are to enable jpeg and png support in GD Lib – you will need LibJPEG and LibPNG installed previously to enable GD. The MySQL line is if you need MySQL. You will need MySQL installed and running.

If you want a PHP.ini file then enter this. It’s not required though.

% sudo cp php.ini-dist /usr/local/lib/php.ini

Step 4: Configuring Apache----------The next bit is to configure Apache to load PHP files properly. Add it below the file’s current contents. The httpd.conf file is located at /apache2/conf/httpd.conf

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php

Also, You now have a choice. By default your new document root will be /apache2/htdocs. If you want to change this back to the Apple default of /Library/WebServer/Documents you need to open the httpd.conf file (/apache2/conf/httpd.conf) and change the following:

<Directory “/apache2/htdocs”>


<Directory “/Library/WebServer/Documents”>

Similarly, Apache 2 will now point to the UNIX standard user directory. Which means if you type http://::1/~user/ it will point to the ~/public_html directory. In Mac OS X the usual standard is ~/Sites. If you wish to change this you need to access the httpd.conf file once again and change

UserDir public_html


UserDir Sites

Step 5: Starting and Stopping Apache 2----------If all went well you should now have a working Apache 2 installation. However, this will not work with the Web Sharing option in System Preferences. Before you continue, please make sure the option in System Preferences is set to “Off”.

To start Apache 2:

sudo /apache2/bin/apachectl start

To stop Apache 2:

sudo /apache2/bin/apachectl stop

You will need to switch this on everytime your restart your Mac. Or, you can use another PHPmac tutorial to enable Apache 2 as the default OS X server. Additional Useful Apache2 Config Settings.

Hope all goes well… if, however, you hit a wall or you need help, however trivial, please contact support. Click Here. Please note; a PHPmac login is required.

-James Pelow

Some frequent Issues:

Q: I recieve the following error message while running the Apache configure command:

Creating Makefile in src
+ configured for Darwin platform
Error: could not find any of these C compilers
anywhere in your PATH: gcc cc acc c89
Configure terminated

A: You need to install the Apple supplied Developers’ Tools. These come on a CD in your Mac OS X box or in the Applications folder if you’ve just bought your Mac recently

Q: I received an error message regarding the absence of LibXML2

A: Building and Installing libXML2 (Required for PHP 5)

libXML2 is now required by PHP. The building of libXML2 is releativly simple, but it takes for ever and a day to compile. So be prepared to go and make yourself a coffee and maybe dinner. Most people should have this, it was included in an Apple Security update a while back. However, many people have been encountering this problem so I have added directions here.

First step is to download the source then Untar it. We will make a directory to do this:

% cd ~/Desktop
% mkdir libxml2build
% cd libxml2build
% curl -O
% gnutar -xzf libxml2-2.6.7.tar.gz
% cd libxml2-2.6.7

We are now in the libxml2-2.6.7 source directory. From here it’s a simple compile and install.

% ./configure
% make
% sudo make install
% sudo ranlib /usr/local/lib/libxml2.a

libXML2 is now installed. Go Back and try configure PHP again, with the line –with-libxml-dir=/usr/local in your PHP configuration command.

Leave a comment

Your email address will not be published. Required fields are marked *