Due to some limitation I faced with Xampp I finally decided to compile PHP5 native on my mac. Entropy was a best option for mac till Leopard was released. Since Leopard came with php built in entropy was no more available. After Googling for a long time and breaking my head with errors for 7 long hours I finally got it working perfectly like how I wanted it. These are some of the steps I followed to compile the same. I tested the same steps in 2 macs and it was working fine. I cannot guarantee that these steps would work for everyone.

Step 1

You need to have Xcode installed on your mac. In my case I had Xcode 3.1.2 installed. You can install from your Leopard DVD or you can install iPhone SDK.

Step 2

Download and install the latest Mysql database server.

Step 3

Install Fink. You can download the version 0.9.0 which I used for compiling from here. Once you have installed open terminal and issue the following commands.

# sudo fink selfupdate
# sudo fink update-all

The above two commands will update the needed files for fink library to work properly. Once this is done you can install needed libraries for php by issuing the following command

# sudo fink install libjpeg libtiff libpng3 libxml t1lib5 libmcrypt libmhash mysql15-dev curl wget

Step 4

Install FrontBase if it is needed for you. It is installer file you can download it from here. If you don’t want to use this database system you can remove the option ‘–with-fbsql’ from the php configure command.

Step 5

Install Freetds if you want use MS-SQL in PHP5.

# sudo su
# curl -O http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
# tar xvzf freetds-stable.tgz
# cd freetds-0.82/
# ./configure && make && sudo make install

Incase if you feel this is not needed for your installation you can remove the option ‘–with-mssql’ and ‘–enable-dbase’ from the php configure command.

Step 6

Install Imap Client libraries files. You need this lib to be installed if you wish to compile imap. If you don’t want you can remove the option ‘–with-imap’ and ‘–with-imap-ssl’. Further reading on this topic visit here.

# sudo su
# curl -O ftp://ftp.cac.washington.edu/imap/c-client.tar.Z
# tar xvzf c-client.tar.Z
# cd imap-2007e/
# make oxp
# cd c-client/
# cp *.h /usr/local/include
# cp *.c /usr/local/lib
# cp c-client.a /usr/local/lib/libc-client.a

Step 7

Install gettext. This is a must for lot of open source projects and for localization.

# sudo su
# curl -O ftp://ftp.gnu.org/gnu/gettext/gettext-0.17.tar.gz
# tar xvzf gettext-0.17.tar.gz
# cd gettext-0.17
# cd gettext-tools/
# ./configure
# make
# make install

Step 8

Install freetype. You need if you wish to load free type fonts in GD.

#sudo su
# wget http://mirrors.zerg.biz/nongnu/freetype/freetype-2.3.8.tar.gz
# tar xvzf freetype-2.3.8.tar.gz
# cd freetype-2.3.8
# ./configure
# make
# make install

Step 9

I think we are pretty there and now it is time to compile the big boss the PHP itself.

# sudo su
# wget http://www.php.net/get/php-5.2.8.tar.gz/from/in.php.net/mirror
# tar xvzf php-5.2.8.tar.gz
# cd php-5.2.8
# ./configure --prefix=/usr/local/php5.2.8 --with-apxs2 --with-config-file-scan-dir=/usr/local/php5.2.8/php.d --with-openssl=/usr --with-zlib=/usr --with-gd --enable-gd-native-ttf --with-jpeg-dir=/sw --with-jpeg-dir=/sw --with-png-dir=/sw --with-zlib-dir=/usr --with-ldap --with-xmlrpc --with-iconv-dir=/usr --with-snmp=/usr --enable-exif --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-calendar --enable-bcmath --with-bz2=/usr --with-curl --with-kerberos=/usr --with-libxml-dir=/sw --with-xsl --with-t1lib=/sw --with-mcrypt=/sw --with-mhash=/sw --with-mysql=/sw --with-mysqli --with-pdo-mysql=/sw --enable-zip --with-imap --with-imap-ssl --with-gettext --with-curl=/sw --with-pear --with-regex --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv=shared,/opt/local --enable-dbase --enable-sqlite-utf8 --with-fbsql
# make
# make install

If you have completed till the above step without any error means that you have successfully installed PHP5. If you restart your apache server from system settings the server might not work for you. Since it might conflict a bit due to various architecture problems in apache and php build. To over come this issue you need to re-compile apache. You can do it by issuing the following commands. Further reading on this issue.

Step 10

Recompile Apache 2.

# sudo su
# wget http://apache.siamwebhosting.com/httpd/httpd-2.2.11.tar.gz
# tar xvzf httpd-2.2.11.tar.gz
# cd httpd-2.2.11/
# ./configure --enable-layout=Darwin --enable-mods-shared=all
# make
# make install

screenshot1screenshot2

Once everything is done you should be able to run PHP. Have fun compiling your own native PHP on your mac πŸ˜‰ .!!!