Go back to the main page

Compiling PHP 5.2 on OSX Lion

This article is over 2 years old. Proceed with caution.

Regards ♨ – Minimul



This doesn't look that hard but I was caught forever getting the libjpeg(a|so) not found php compile error. What I believe got me past that error is the php compile switch --enable-static or even possibly the --disable-shared switch. I also had quite a run in with the iconv extension (see below). This was a nightmare and I almost quit.


  • OSX Lion
  • XCode 4.2
  • MacPorts

1. Compile dir

This not required but I have a ~/Compile dir which I will be working from

mkdir ~/Compile

2. Compile libjpeg.

I used v1.7 and you can get it here.

cd ~/Compile
wget or curl the libjpeg.tar.gz and uncompress
cd libjpeg-1.7
make && make install

3. Save the current libphp5.so

sudo cp /usr/libexec/apache2/libphp5.so /usr/libexec/apache2/libphp5.so.original.53

4. Compile PHP

I downloaded the latest at this time of writing, which is 5.2.17. Some notes about the configure command. I had XCode installed which has both libpng and libfreetype so I just used those, which are in /usr/X11/lib. However, I only used the Xcode ones after I could get the configure to pass. I kept getting "libpng(a|so) not found" and then libfreetype(a|so) not found. I believe this was because the .dylib was not getting generated on the libpng and libfreetype hand compile.

./configure --with-mysql=/usr/local/mysql --with-zlib --enable-soap --with-apxs2 --disable-iconv --enable-ftp --enable-mbstring --prefix=/usr/local/php52 --with-gd --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --with-jpeg-dir=/usr/local --with-png-dir=/usr/X11 --with-freetype-dir=/usr/X11 --with-curl --enable-xmlreader --enable-xmlwriter --enable-zip --with-kerberos --enable-static --disable-shared

sudo make install

5. Note on iconv

You will notice the --disable-iconv. I could not for the life of me get iconv compiled. I tried everything that I could search for including: hacking the Makefile; and hacking the ext/iconv/iconv.c file. Therefore if you are searching for the error:

Undefined symbols for architecture x86_64:
  "_libiconv_open", referenced from:
      _do_convert in gdkanji.o
      _convert in encodings.o
  "_libiconv", referenced from:
      _do_convert in gdkanji.o
      _convert in encodings.o
  "_libiconv_close", referenced from:
      _do_convert in gdkanji.o
      _convert in encodings.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [libs/libphp5.bundle] Error 1

I can't help you. However, you may realize, as I did, that you don't need the iconv extension.


For whatever reason the compiled php cli binary was named "php.dSYM". I made a symbolic link instead of renaming.

sudo ln -s /usr/local/php52/bin/php.dSYM /usr/local/php52/bin/php

Bonus: Installing APC and PDFLib from pecl

cd /usr/local/php52
sudo ./bin/pecl install apc # ignore warning about php suffix
# PDFLib
sudo port install pdflib
sudo ./bin/pecl install pdflib
    -path to pdflib installation? /opt/local
Comment on this article?