Building and Installing Apache 2.2.0 and PHP 5.1.2 on Mac OS X 10.4.4

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.2 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 http://apache.seekmeup.com/httpd/httpd-2.2.0.tar.gz

% gnutar -xzf httpd-2.2.0.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.0

% 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 http://ie.php.net/distributions/php-5.1.2.tar.gz

% gnutar -xzf php-5.1.2.tar.gz

% cd php-5.1.2

% 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

% 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. The MySQL line is if you need MySQL. You will need
MySQL installed and running. Please note, due to a bug with PHP, 64bit MySQL
will not compile in, revert to 32bit.

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"

to

DocumentRoot "/Library/WebServer/Documents"

and

<Directory "/apache2/htdocs">

to

<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



to

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

PHPmac

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 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 ftp://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.7.tar.gz

% 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.


By James Pelow

PHPmac