A few people find it hard to compile PHP on Mac OS X and prefer using tools like Mamp or MacPorts.
Even though MacPorts is useful I prefer compiling PHP by myself, here is a step by step tutorial.
Note 1: this tutorial has been written for Mac OS X 10.4 but I am sure it is the same for more recent versions.
Note 2 : with the configuration directives described below PHP is compiled in CGI/FastCGI mode if you want to use it as an Apache module this only thing you have is to do is to use the following extra argument :
--with-apxs2=/path/to/apache2/apxs
1. Downloading PHP 5.3
wget http://fr3.php.net/get/php-5.3.0.tar.gz/from/fr.php.net/mirror
2. Extracting the tarball
tar zxvf php-5.3.0.tar.gz
3. Configuring PHP
cd php-5.3.0
./configure \
–prefix=/opt/php5 \
–enable-exif \
–with-gd=/opt/local \
–with-freetype-dir=/opt/local \
–with-jpeg-dir=/opt/local \
–enable-gd-native-ttf \
–with-png-dir=/opt/local \
–with-t1lib=/opt/local \
–with-zlib=/opt/local \
–with-mysql=/usr/local/mysql \
–with-mysqli \
–with-ldap \
–enable-mbstring \
–with-mcrypt=/opt/local \
–with-bz2=/usr/bin \
–enable-ctype \
–enable-dom \
–enable-libxml \
–with-iconv \
–enable-pdo \
–with-pdo-sqlite \
–enable-posix \
–enable-simplexml \
–enable-xml \
–with-zlib \
–with-curl \
–enable-filter \
–with-pdo-mysql=/usr/local/mysql \
–with-openssl \
–with-xmlrpc \
–with-xsl \
–enable-soap \
–enable-ftp \
–enable-pcntl \
–enable-shmop
4. Compiling and installing
make && sudo make install
You can go to the kitchen and get a tea or a coffe while it is compiling.
If you do not like tea or coffee you can also try other fun activities like the following :

Source : http://xkcd.com/303/
Back from the kitchen, you are done. PHP 5.3 is now compiled and installed on your machine.
You can of course use a few extra CFLAGS or options to the configure script if you want to, but the most basic steps are here and you now know the required steps
Now a small tip, let us say I want to compile with the --with-mysql=/path/to/wrong/mysql/directory argument but unfortunately the configure script fails with such an error message :
configure: error: Cannot find MySQL header files under /path/to/wrong/directory.
Note that the MySQL client library is not bundled anymore!
How to find the correct path and fix the problem ?
1. I know that the mysql extension is available in the ext/mysql directory
2. the configuration related to this module is in config.m4
By opening ext/mysql/config.m4 I discover (line 77) that the mysql.h header is required and it is searched in the following directories (still on line 77) :
- /usr/local
- /usr/
The only thing I have to do is searching for mysql.h. Since I use the official MySQL binary I know it is installed in /usr/local/mysql/ so if I look in /usr/local/mysql/include/ I find the required mysql.h file. The config.m4 file searches for /include/mysql.h (line 81) so the only thing I have to do is to correct my –with-mysql argument and use --with-mysql=/usr/local/mysql. By relaunching the configure script it worked and we have been able to compile PHP with MySQL successfully
Since you now have compiled PHP by yourself the only limit for you now is your imagination












