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
Once everything is done you should be able to run PHP. Have fun compiling your own native PHP on your mac 😉 .!!!
Hello and thank you for this tuto !
I will try to compile (again, but with success?) with your aid.
i wonder why anyone has made à package installer after compile it ?
i also want to have the gd and pdflib libraries compiled with php 5.2.8, i suppose that is the same think that the other libs?
and last (but not least) i would like to compile in Universal binary, and install directly on another computer, how could i do that?
Thank a lot for this in any case 😉
Best regards,
Nicolas from France
Thanks for the great walk-through!! It was easy and explained well.
Howdy! Good job on the tutorial. Have you ever checked out Macports? The package management application for the mac OSX. It may save you some time in the future with stuff like this.
-peace
@Jared Folkins
Yes I know it is there. I have never compiled anything o0n mac so far. This was my first time and I it was a good experience 🙂
For sure! Just wanted to make sure you knew. -take care
The useful thing about this tutorial was that it also installed the php ldap module which doesn’t come with macports by default.
Great help for me.
Thank you very much and keep good job.
does anybody know of a guide to use macports for the latest version of PHP on mac Leopard?
After few days I released that I had not installed Tidy for my installation. So I installed Tidy using macports
# sudo /opt/local/bin/ports install tidy
After installing you can reconfigure your installation –with-tidy option.
for me everything worked fine instead of the outdated freetype 2.3.8, I took freetype 2.3.9
but at the almost end at step after the ./configure of php it didn’t do the make with
this error message: configure: error: Cannot locate header file libintl.h
what shall I do know?
It looks like php 5.2.9 will be the choice. Did you ever verify that your tutorial will work also with that. I would like to know that before doing the same on another machine which didn#T work at my first try.
greetings
_thomas
my third try brought me until this error:
/freetype-2.3.8/php-5.2.8/sapi/apache2handler/mod_php5.c:36: warning: data definition has no type or storage class
make: *** [sapi/apache2handler/mod_php5.lo] Error 1
make install won’t continue
why?
Please note: Leopard combo update 10.5.7 will overwrite the installation. Please follow the same steps and it worked for me 😉
Same as Imthiaz… the update today broken my installation, but the steps above, including recompiling Apache did the trick.
Thanks for the tutorial.
I get:
checking whether build with IMAP works… no
and then a configure error on php.
The config log says that libc-client.a is not of required architecture.
Any ideas?
I have the stock apache on a MBP/C2D, which might be running as a 32bit binary, so, my guess is that I might have compiled the imap library as a 64bit and then PHP just said no. Will try again later, probably rebuilding all 64-bit 🙂
Thanks for replying!
Great job man! I need to connect to an old Sybase ASA server and this works flawlessly!
Cheer!
Hi Imthiaz,
I want to connect PHP with oracle database 10.2 installed on the mac os server 10.5.5.
As we all know that php and apache2 is in built with mac.
I configure mac for php and saw the phpinfo (). it is fine. but when to try to connect oracle database with ociconnect (). its showing error.
Can you help me in this regard.
–Shyam
Hi Imthiaz,
I enabled php on mac 10.5.5 server. Now its first page is displaying using phpinfo().
Now I want to connect php with oracle database installed in same machine. I try to connect it using oci_connect () but unable to do so. it is showing error ” Fatal error: Call to undefined function oci_connect() “.
Can you suggest how to over come on this??
Thanks,
Shyam
Thank you this worked very well. My only comment is that I had to specify the path for the gettext stuff. So when you go to configure php, make sure that the “–with-gettext” option is really: “–with-gettext=/sw”. Otherwise it couldn’t find libintl.h.
The other discrepancy I found was the link for the apache tarball did not work. I was able to find a newer version of apache here: http://www.alliedquotes.com/mirrors/apache/httpd/httpd-2.2.14.tar.gz
If that doesn’t work, there’s always this page: http://httpd.apache.org/download.cgi
Thanks again!!
Sarah
Cheers man, worked fine on Snow Leopard a moment ago.