Blog Compile PHP 5.2 on OSX 10.6 (Snow Leopard)

Since OSX 10.6 (Snow Leopard) I've gone supposedly easy way using MAMP as dev server. I never really liked it but now it was insane: turned out MAMP is so hogging the system on OSX 10.6. The only way was to have some native 64-bit server running PHP 5.2.x. I really feel that 64-bit apps are much faster at least at releasing some valuable RAM.

I don't yet like MacPorts, not sure for what reason (yep, I'm picky). So the only way was to compile PHP and libraries by myself. Thanks internets (Drew, Stanley, Stewart and others) for tips! Here is my take:

#0. I would install official MySQL OSX binary from (64-bit DMG version).

#1. Backup your original Snow Leopard PHP 5.3:
sudo cp /usr/libexec/apache2/ /usr/libexec/apache2/

#2. Create src directory in your user folder where all needed files will be stored initially:

mkdir ~/src

#3. Install freetype

cd ~/src/
curl -O
tar xjf freetype-2.3.12.tar.bz2
cd freetype-2.3.12/
sudo make install

#4. Install t1lib (TrueType)

cd ~/src/
curl -O
tar xzf t1lib-5.1.2.tar.gz
cd t1lib-5.1.2/
make without_doc
sudo make install

#5. Install libjpeg

cd ~/src/
curl -O
tar xfz jpegsrc.v7.tar.gz
cd jpeg-7/
cp /usr/share/libtool/config/config.sub .
cp /usr/share/libtool/config/config.guess .
./configure --enable-shared
sudo make install

#6. Install libpng

cd ~/src
curl -O
tar xfz libpng-1.2.37.tar.bz2
cd libpng-1.2.37
sudo make install

#5. Install mcrypt

cd ~/src
curl -O
tar xfz libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --disable-posix-threads --enable-dynamic-loading
sudo make install

#6. Install PHP. Well, here is an interesting turn: 5.2.13 failed to compile, so I'm using 5.2.12:

cd ~/src
curl -O
tar xfz php-5.2.12.tar.bz2
cd php-5.2.12

Important part: due to some inconsistency in php/osx you have to change a line in iconv.c from #define iconv libiconv to #define iconv iconv (around line 195):

nano ext/iconv/iconv.c

#or a bit more friendly if you have textmate

mate ext/iconv/iconv.c

Now the easy but processor consuming part:

./configure \
    --prefix=/usr/local/php5 \
    --with-iconv \
    --with-apxs2 \
    --with-freetype-dir=/usr/local/lib \
    --with-t1lib=/usr/local/lib \
    --with-gd \
    --with-zlib \
    --with-jpeg-dir=/usr/local/lib \
    --with-png-dir=/usr/local/lib \
    --with-curl \
    --with-mcrypt \
    --with-xmlrpc \
    --with-pdo_mysql=/usr/local/mysql \
    --with-mysql=/usr/local/mysql/ \
    --with-mysqli=/usr/local/mysql/bin/mysql_config \
    --enable-soap \
    --enable-exif \
    --enable-pdo \
    --enable-mbstring \
    --enable-gd-native-ttf \

make test
sudo make install

Of course you may alter amount of libraries your PHP setup uses. But I've chosen the ones I really need time to time with my Drupal dev.

UPD: It also might be a good idea to set MaxClients (mpm_prefork_module block) in etc/apache2/extra/httpd-mpm.conf from 150 to 10 or about. I have done it to conserve some RAM on my MacBook for other applications. As otherwise I could see dozens of httpd processes hogging the system which makes the whole thing unresponsive.

The last thing: doing all above we altered "official" Snow Leopard's PHP library, so let's make a backup of what we've done so we can get it back if another software update breaks it:
sudo cp /usr/libexec/apache2/ /usr/libexec/apache2/

Oh, yes, we've saved about 19Mb with newly compiled PHP 5.2.12 vs 5.3 (despite the backups though). Have fun compiling! And leave a comment if anything.

Add new comment

Comments (22)

Thank you so much for such a great write-up! I wanted to let you know that there seems to be a typo in the configure script for the php compilation. Shouldn't there be a '\' at the end of the line "--enable-soap"? Thanks again!

Thanks Jay,

This was really a typo. I just fixed it.

And as of OSX 10.6.3 Apple supplies updated PHP (5.3.1) so my backup line in the bottom of the blog was so helpful :) 5.2.12 was backed up and working in a min.

thanks, you are my hero! :)


Thanks for linking back to my pixelchimp instructions, I just stumbled across this post as I am reinstalling PHP, Mysql for Drupal 5 & 6 on 10.6.3.

I have added a few more updates since I used PHP 5.2.13 & newer libraries, lets hope they work with Drupal :^)

Oh, hey! And thanks.

Actually your article was among the most useful. Peculiar enough how you can find the majority of Drupal related/powered posts on this issue on first pages of Google :)

I'm just trying to keep amount of PHP libs minimal to keep up with "average" hosting setup of my clients. So I'll stick with this PHP configuration for a while.

Acquia Drupal Stack ( is lovely as well actually but not in last versions for me:

I added a 'hacky fix' to get ssh to port forward 8082 to port 80 to make DAMP work on localhost. It's in the comments on I'm not sure how to turn it off though :^) a restart should do.

Yep, it's hacky. But you should be able to put it in .sh and run at startup. Nice idea though!

Me working as a computer, but there was false positive from anti spam. So here is the message James McCarthy mailed in:


this was an excellent write-up! thank you. it worked and now my local dev env. is happy with mcrypt :)

I had to make a few adjustments. the curl url fro freetype is now: and the curl URL for libmcrypt is broken.

i tried but couldn't get it to download so I download, decompressed and moved via finder and then could run configure, make, etc.

Again thanks!

Thanks very much for the how-to. While I was compiling PHP, I received a "mysql configure failed" message, which prevented me from being able to make and install. Any ideas why?


Thanks Tim!

Sorry, missed the step. And just updated the blog post with step #0.

Most probably you missed installing MySQL from official site. Hope it helps.

the launch of the. / configure script of php 5.2.12 I get the following error:

checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... no
checking for mysql_close in -lmysqlclient... no
checking for mysql_error in -lmysqlclient... no
configure: error: mysql configure failed. Please check config.log for more information.

but the socket location is right!
How can I fix?

hi andrey...

this is a super great write-up and for the most part things seemed to go as planned but i do have a couple of questions for you.

when i ran "make test" on php, i received an "expected failed test sumary" like this:

output buffering - fatalism [tests/output/ob_011.phpt]
ob_start(): Ensure unerasable buffer cannot be flushed by ob_flush() [tests/output/ob_start_basic_unerasable_005.phpt]
SPL: ArrayObject::exchangeArray() basic usage with object as underlying data store. [ext/spl/tests/arrayObject_exchangeArray_basic3.phpt]

i did a little googling and found that some others had similar issues, but there was never a clearly defined answer as to if one should proceed with the "make install". did you happen to also get this error?

since i couldn't find that defined answer, i did proceed with the "sudo make install" and it did complete, but now when i run "$ php --version" it is still showing "5.3.2". what happens when you run "$ php --version" on your setup?

any advice you can provide would be much appreciated. i too am a drupal developer, so i need 5.2.x for D6. i had used the "entropy php" package when i was under osx 10.5, but now that i had to upgrade to osx 10.6 due to iphone sdk dev requirements, i am in a bind. i also would rather not have to go the route of MAMP, but if i can't resolve this, i might have to.

thanks in advance for the help and also for the great write-up.


Hey Jon,

Can't really help with your errors exactly. But here is a tip: there are some bugs/incompatibility known with *exactly* this (OSX) Apache version and *exactly* that PHP version. I've chosen 5.2.12 exactly because of this while 5.2.13 was already available. Just try to search this way.

Anyway, if everything is all right with compiling "$ php --version" will show you 5.2.X of course.

What should I do if I want to get back to PHP 5.3 version?
Thanks, great tutoral

just this: sudo cp /usr/libexec/apache2/ /usr/libexec/apache2/ ???
Thanks in advance

If you backed up your 5.3 as in step #1 then yes: sudo cp /usr/libexec/apache2/ /usr/libexec/apache2/

OSX updates my rewrite it to 5.3 as well by the way.


Hi, I am getting the exact same message as jon above when running "make test". I'm on OSX 10.6.4 and all previous steps on your tutorial were successful.

I only installed xcode; Are there any other dev tools that need installing maybe?

Help pls :)

I have this error when running make test (exactly like jon above), osx 10.6.4 and xcode 3.2.4:

Exts skipped    :   45
Exts tested     :   34

Number of tests : 9023              7416
Tests skipped   : 1607 ( 17.8%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :   45 (  0.5%) (  0.6%)
Expected fail   :    4 (  0.0%) (  0.1%)
Tests passed    : 7367 ( 81.6%) ( 99.3%)
Time taken      :  336 seconds

Bug #30638 (localeconv returns wrong LC_NUMERIC settings) (ok to fail on MacOS X) [tests/lang/bug30638.phpt]
Curl_multi_getcontent() basic test with different sources (local file/http) [ext/curl/tests/curl_multi_getcontent_basic3.phpt]
curl_setopt() basic parameter test [ext/curl/tests/curl_setopt_error.phpt]
timezone_abbreviations_list() tests [ext/date/tests/010.phpt]
Test DateTimeZone::listAbbreviations() function : basic functionality [ext/date/tests/DateTimeZone_listAbbreviations_basic1.phpt]
Test DateTime::modify() function : usage variation - Passing unexpected values to first argument $modify. [ext/date/tests/DateTime_modify_variation1.phpt]
Test date_modify() function : usage variation - Passing unexpected values to second argument $format. [ext/date/tests/date_modify_variation2.phpt]
Test gmstrftime() function : usage variation - Checking Preferred date and time representation other than on Windows [ext/date/tests/gmstrftime_variation22.phpt]
Test strftime() function : usage variation - Checking Preferred date and time representation other than on Windows. [ext/date/tests/strftime_variation22.phpt]
Test timezone_abbreviations_list() function : basic functionality [ext/date/tests/timezone_abbreviations_list_basic1.phpt]
Bug #48555 (ImageFTBBox() differs from previous versions for texts with new lines) [ext/gd/tests/bug48555.phpt]
Test imagecolorallocate() function : usage variations  - passing different data types to fourth argument [ext/gd/tests/imagecolorallocate_variation4.phpt]
iconv stream filter [ext/iconv/tests/iconv_stream_filter.phpt]
mcrypt_list_algorithms [ext/mcrypt/tests/mcrypt_list_algorithms.phpt]
mcrypt_list_modes [ext/mcrypt/tests/mcrypt_list_modes.phpt]
Bug #41125 (PDO mysql + quote() + prepare() can result in seg fault) [ext/pdo_mysql/tests/bug41125.phpt]
Bug #44327 (PDORow::queryString property & numeric offsets / Crash) [ext/pdo_mysql/tests/bug44327.phpt]
Test session_encode() function : error functionality [ext/session/tests/session_encode_error2.phpt]
Test session_save_path() function : variation [ext/session/tests/session_save_path_variation5.phpt]
SimpleXML: XPath [ext/simplexml/tests/008.phpt]
SPL: DirectoryIterator test getGroup [ext/spl/tests/DirectoryIterator_getGroup_basic.phpt]
SPL: Spl Directory Iterator test getOwner [ext/spl/tests/DirectoryIterator_getOwner_basic.phpt]
SPL: Spl File Info test getGroup [ext/spl/tests/SplFileInfo_getGroup_basic.phpt]
SPL: Spl File Info test getOwner [ext/spl/tests/SplFileInfo_getOwner_basic.phpt]
Sort with SORT_LOCALE_STRING [ext/standard/tests/array/locale_sort.phpt]
Test umask() function : usage variation [ext/standard/tests/file/umask_variation3.phpt]
Test function getservbyname() by substituting argument 2 with emptyUnsetUndefNull values. [ext/standard/tests/general_functions/getservbyname_variation10.phpt]
Test function getservbyname() by substituting argument 2 with boolean values. [ext/standard/tests/general_functions/getservbyname_variation9.phpt]
proc_nice() basic behaviour [ext/standard/tests/general_functions/proc_nice_basic.phpt]
Test mail() function : basic functionality [ext/standard/tests/mail/mail_basic2.phpt]
Test mail() function : variation force extra parameters [ext/standard/tests/mail/mail_variation2.phpt]
highlight_file() and output buffer [ext/standard/tests/strings/006.phpt]
php_strip_whitespace() and output buffer [ext/standard/tests/strings/007.phpt]
Test nl_langinfo() function :  unexpected inputs for '$tem' argument [ext/standard/tests/strings/nl_langinfo_variation1.phpt]
Test setlocale() function : basic functionality - setting system locale to a specific [ext/standard/tests/strings/setlocale_basic1.phpt]
Test setlocale() function : basic functionality - set locale using an array [ext/standard/tests/strings/setlocale_basic2.phpt]
Test setlocale() function : basic functionality - passing multiple locales as argument [ext/standard/tests/strings/setlocale_basic3.phpt]
Test setlocale() function : usage variations - passing multiple valid/invlaid locales as argument [ext/standard/tests/strings/setlocale_variation1.phpt]
Test setlocale() function : usage variations - setting system locale = 0 [ext/standard/tests/strings/setlocale_variation3.phpt]
Test strtolower() function [ext/standard/tests/strings/strtolower.phpt]
Test strtoupper() function [ext/standard/tests/strings/strtoupper1.phpt]
Test strptime() function : basic functionality [ext/standard/tests/time/strptime_basic.phpt]
Bug #42189 (xmlrpc_get_type() crashes PHP on invalid dates) [ext/xmlrpc/tests/bug42189.phpt]
Bug #51288 (CVE-2010-0397, NULL pointer deref when no <methodName> in request) [ext/xmlrpc/tests/bug51288.phpt]
xmlwriter_open_uri with PHP_MAXPATHLEN + 1 [ext/xmlwriter/tests/bug48204.phpt]

output buffering - fatalism [tests/output/ob_011.phpt]
ob_start(): Ensure unerasable buffer cannot be flushed by ob_flush() [tests/output/ob_start_basic_unerasable_005.phpt]
SPL: ArrayObject::exchangeArray() basic usage with object as underlying data store. [ext/spl/tests/arrayObject_exchangeArray_basic3.phpt]
Bug #39863 (file_exists() silently truncates after a null byte) [ext/standard/tests/file/bug39863.phpt]

Ok not sure about this but, from terminal "php --version" says 5.3.2, but phpinfo() loaded within the browser on localhost says 5.2.12.

Why is terminal showing the wrong php version?

HArch, thanks for follow up on this one. I didn't check the apache vs terminal versions when I was compiling. But I'd say the same as guys on stackoverflow: you can have a few legit instances of PHP on the same system.

And if your apache picks 5.2.x it's just fine for your local web dev. So all your localhost applications will run under 5.2.x.