Building and Installing Apache 2.2.4 and PHP 5.1.4 on Mac OS X 10.4.6

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 Mac OS X 10.4.6 for PPC or INTEL WITH ALL latest Security Updates. Special Note for Intel Macs: Please make sure you install the developers’ tools that came with your mac, do not use old PPC developers’ tools. Mac OS X Server is not supported

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.3 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.2.4.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.2.4
% 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.4.tar.gz
% cd php-5.1.4
% sudo mkdir /apache2/php

Once all that’s done, we will configure and compile PHP (Remember % represents the prompt, it should not be entered).

% ./configure \
% –prefix=/apache2/php \
% –with-zlib \
% –with-xml \
% –with-ldap=/usr \
% –enable-cli \
% –with-zlib-dir=/usr \
% –enable-exif \
% –enable-ftp \
% –enable-mbstring \
% –enable-mbregex \
% –enable-dbx \
% –enable-sockets \
% –with-iodbc=/usr \
% –with-curl=/usr \
% –with-mysql=/usr/local/mysql \ (optional, required MySQL)
% –with-gd \ (optional, requires jpeg + png)
% –with-jpeg-dir=/usr/local \ (optional)
% –with-png-dir=/usr/local \ (optional)
% –with-apxs2=/apache2/bin/apxs
% sudo 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. Please note, due to a bug with PHP, 64bit MySQL will not compile in, revert to 32bit. Also, due to a different bug, the latest version of MySQL should not be used. Please revert to an older version.

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

% sudo cp php.ini-dist /apache2/php/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. Make sure to use a flat text editor like BBEdit or Pico in the command line.

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:

DocumentRoot “/apache2/htdocs”


DocumentRoot “/Library/WebServer/Documents”


<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 your user folder. In Mac OS X the usual standard is ~/Sites. If you wish to change this you need to access the /apache2/conf/extra/httpd-userdir.conf file 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. This tutorial also contains important settings to secure your server, all are recommended to follow this

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 receive 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 required by PHP. It comes bundled in Tiger and if you met the requirements of the article then you shouldn’t have this problem. 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.

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.22.tar.gz
% cd libxml2-2.6.22

We are now in the libxml2-2.6.22 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.

Enabling Apple’s Supplied PHP in OS X 10.4 Tiger

Alert!: Attention: Cet article/tutorial est ‰gé de plus de 45 jours. Ainsi les informations qu’il contient peuvent être, maintenant, dépassé. Merci de lire toutes les informations qu’il contient pour vous assurez que cet article fonctionnera bien sur votre système

The first thing that many will want to do after they install their shiny new copy of OS X 10.4 Tiger, will no doubt be to restore PHP to their WebServer. This is the quickest, easiest way, that anyone can manage that end.

This tutorial demonstrates how to activate Apple’s PHP, as supplied, out of the box. This is a very quick and easy method that will suit beginners, and will keep more advanced users happy while they wait for the energy to build and install PHP from source.

1. Step One
Locate the “Terminal” application. It comes with every OS X installation and can be found in the Utilities folder, in the Applications folder on your Mac OS X main drive. Open this application.

2. Step Two
Once in the terminal you will be greeted with something like the following text:

Last login: Sat May 7 00:28:29 on ttyp1
Welcome to Darwin!
ibook:~ username$

The $ represents the prompt, or the place that you, the user, types your input. To enter a command; type it in, and press Enter.

3. Step Three
Enter the following commands (not including the $. Remember, they represent the prompt) one line at a time, pressing Enter after each line:

$ cd /etc/httpd
$ sudo pico httpd.conf

4. Step Four
In the last command, we opened the Apache Web Server configuration file in a text editor called “Pico”. You will need to enter your password. We now want to edit this file to enable PHP.

Press Control-w on your keyboard, then enter “php” and press Enter. This will search for the first occurrence of “php” in the Apache configuration file.
You should come to the following line.

# LoadModule php4_module libexec/httpd/

Remove the # (hash sign) from the beginning of the line. Press Control-w again, and then Enter. Repeat this until you reach the following line:

# AddModule mod_php4.c

Once again, remove the # (hash sign) from the start of the line.

5. Step Five
We have now made all necessary changes to the file. Now we must save these changes. Press Control-o (the letter, not zero) and then Enter. The file is now saved. Press Control-x to exit Pico.

6. Step Six
The last step is simply to restart Apache, so that the changes we made to the configuration file take effect. You can simply use the “Sharing” System Preference Pane to restart Web Sharing. Or you can enter the following command in the terminal:

$ sudo apachectl restart

You may need to reenter your password.

That’s it, PHP will now work as part of Apache.

If you’re having problems you can use PHPmac support to get free one-on-one support via email.

*Requires Login