Submitted by Pixel Chimp on Wed, 02/09/2009 - 21:12

Snow Leopard ships with the latest version of PHP, version 5.3. Unfortunately Drupal 6 will produce error notices due to the use of deprecated functions. It seems the solution is to ‘hack Drupal core’ or use an older version of PHP. It seems likely that Drupal 5 won’t be updated to support PHP 5.3.

To be able to run local test versions of Drupal 5 & 6 it makes sense to install another version of PHP. I tried the Entropy PHP package, but it didn’t want to work, I suspect the Entropy forums will lead to a working package or fix sometime soon.

Requirements for Drupal

  • Mysql 5.x
  • PHP 5.2.x with libraries
    • GD
    • Freetype
    • libpng
    • Mbstring Extension
    • uploadprogress
  • Apache 2
    • ModRewrite (for clean URLs)

Apple Developer Tools are required for compiling source code, and it helps if you can navigate around the Terminal.

I based the process on guides on the following sites, check them out if you need more info…

Compiling PHP with OCI8/Oracle, Apache and MySQL on Mac OS X Leopard

Hivelogic - Installing MySQL on Mac OS X

Install PHP 5.3, Apache2, GD, MySQL 5.1 on OSX Leopard (10.5.7) - PHP/MySQL Development

The plan is to install PHP 5.2.10 and use the built in version of Apache 2. It shouldn’t require major changes to the built in Apache incase an Apple update breaks our changes. If you want to be ultra cautious a second copy of Apache can be installed, but the web sharing checkbox in system preferences wouldn’t be able to control it. Keep a backup before you run Software update or install binaries is a good idea.

My mac has a Core 2 Duo processor so all the required libraries will need to run in 64bit mode (or PHP, Mysql & Apache will need to be recompiled to 32bit mode).

The compiled software will be installed in /usr/local/. Source code will be saved in ~/src.

Installing Mysql

Start by adding the install location to you path, add this to ~/.bash_profile

export PATH="/usr/local/mysql/bin:$PATH"

Open a new window or do . ~/bash_profile ro reload into current shell.

cd ~/src

curl -O ysql-5.1.37.tar.gz


tar xzf mysql-5.1.37.tar.gz

cd mysql-5.1.37

CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fno-omit- frame-pointer -felide-constructors -fno-exceptions -fno-rtti"


./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared


Install Mysql

sudo make install

Setup user database

sudo mysql_install_db --user=mysql

sudo chown -R mysql /usr/local/mysql/var

Set Mysql to launch on startup

sudo touch /Library/LaunchDaemons/com.mysql.mysqld.plist

sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist

sudo pico /Library/LaunchDaemons/com.mysql.mysqld.plist

Paste in the plist text below & save (ctrl+x)

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ""> <plist version="1.0"> <dict>















sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist

Look for a mysql process in activity viewer, or check the logs for errors.

**Update: **The default mysql socket is located in /tmp/mysql.sock, but PHP will expect this to be located in /var/mysql/mysql.sock. It is simplest to sym-link the expected location to the correct location.

sudo mkdir /var/mysql

sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Install shared libraries


cd ~/src/

curl -O

tar xjf freetype-2.3.9.tar.bz2

cd freetype-2.3.9/



sudo make install


cd ~/src/

curl -O

tar xzf t1lib-5.1.2.tar.gz

cd t1lib-5.1.2/


make without_doc

sudo make install


cd ~/src/

curl -O http://www.ijg.o../../../../files/jpegsrc.v6b.tar.gz

tar xfz jpegsrc.v6b.tar.gz

cd jpeg-6b/

cp /usr/share/libtool/config/config.sub .

cp /usr/share/libtool/config/config.guess .

./configure --enable-shared


Update: Create directories before attempting install to prevent error 71 as noted in the comment by Tehkemo below and on


mkdir -p /usr/local/include
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
mkdir -p /usr/local/man/man1

sudo make install


cd ~/src

curl -O

tar xfz libpng-1.2.39.tar.gz

cd libpng-1.2.39



sudo make install


cd ~/src

curl -O ypt-2.5.8.tar.gz

tar xfz libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure --disable-posix-threads --enable-dynamic-loading


sudo make install

Install PHP

cd ~/src

curl -O

tar xfz php-5.2.10.tar.bz2

It is worth adding the configure command below to a shell script to make reuse & modifications easy, add a ‘cd ~/src/php-5.2.10/' before the configure command and execute it.

./configure \

--prefix=/usr/local/php5 \

--without-iconv \

--with-apxs2 \

--enable-pdo \

--enable-mbstring \

--enable-gd-native-ttf \

--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-pdo_mysql=/usr/local/mysql \

--with-mysql=/usr/local/mysql/ \


Now a change to the Makefile is needed, see this for more info

Errors linking libresolv when building PHP 5.2.10 from source on OS X - Stack Overflow

EXTRA_LIBS = […lots of libs here…]

and add -lresolv to this line like this:

EXTRA_LIBS = -lresolv […lots of libs here…]

And then

cd ~/src/php-5.2.10


make test


sudo make install [/code]

**Update: **Make failed for me with PHP 5.2.13, with the following error…

Undefined symbols: “_png_check_sig”, referenced from: _php_gd_gdImageCreateFromPngCtx in gd_png.o ld: symbol(s) not found collect2: ld returned 1 exit status make: *** [libs/libphp5.bundle] Error 1

The fix can be found at Building a Mac OS X Server 10.6: Step 1, Adventures With PHP.

Start web sharing in the System Preferences and you should now have a working copy of Apache with PHP 5.2.10. Add a file containing <?php phpinfo();?> to your sites to check this from your browser.

Update: **(see comment by nick) **If the server is failing to load PHP check that the PHP binary is named correctly in /usr/local/php5/bin, it should be called ‘php’ not ‘php.dSYM’

It can be fixed it with a symbolic link…

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

I expected to need to add the php module to Apache’s config file, but it seems the install process had already done this, probably due to the ‘--with- apxs2’ argument.

If the browser shows the code not the phpinfo add the following to /etc/apache2/httpd.conf

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

I also activated the virtual hosts by adding this to the httpd.conf

Include /private/etc/apache2/extra/httpd-vhosts.conf

Install upload progress

I forgot to do this first time, but it meant I got to use PECL and found a bug to fix. See PEAR Forum for more details or PEAR Blog Fixing “unsupported protocol”

cd /usr/local/php/lib/php/.channels

cd sudo /usr/local/php5/bin/pecl config-get php_dir``

sudo mv .channels .channels-broken

sudo /usr/local/php5/bin/pecl update-channels

Or replace the .channels with the versions posted in the forums.

sudo /usr/local/php5/bin/pecl channel-update

Get the upload progress library

sudo /usr/local/php5/bin/pecl install uploadprogress

Enable the module by in /usr/local/php5/lib/php.ini (I needed to copy the default php.ini to /usr/local/php5/lib)

sudo cp /etc/php.ini.default /usr/local/php5/lib/php.ini

Add the following

… and we are done.


Doesnt worked for me!

Submitted by tehkemo on Fri, 11/09/2009 - 17:29.

Ive ended installation with GD library - when I put sudo make install - it only shows up error 71 I think..

if any1 get this (or other solution) working, please msg me…

tehkemo .at.


Tehkemo, A quick Google

Submitted by Pixel Chimp on Sat, 19/09/2009 - 00:21.


A quick Google found this page, the answer to error 71 is possibly in the comments. It looks like the /usr/local/man directory may not exist.

I suspect I had already installed something that added manuals to that location.

If you can confirm it works I’ll update the post with details.


Submitted by tehkemo on Sun, 11/10/2009 - 20:36.

Hey, sorry for late response, I was quite busy, but today I tried to compile PHP 5.2.10, MySQL, Virtual host and some other libraries, all worked fine, thank you, and if you do not mind, I would, when I set up my blog, post ur guide, of course I’ll post source (your website).

Best regards,

Tommy :)


Submitted by nick on Sun, 20/09/2009 - 04:39.

Thanks for this post, saved me a lot of hassle. Everything worked fine except the php cli which didn’t seem to work and a quick check in the /usr/local/php5/bin directory reveals no actual php executable. After hunting around it turns out that the php.dSYM file is actually php, not sure what dSYM means though.

So for anyone else having this problem, a quick call to sudo ln -s php.dSYM php inside the /usr/local/php5/bin directory will get the php command line going again.


Updated post

Submitted by Pixel Chimp on Mon, 12/10/2009 - 21:50.

I updated the post to show the changes suggested by Nick and Tehkemo. Thanks for posting them.

Feel free to link back here Tommy.

Locating the PHP Makefile…

Submitted by renbucholz on Mon, 26/10/2009 - 14:44.

Dear Pixel Chimp,

Thanks so much for this detailed guide! I have a dumb question. When I get to the part about editing the PHP Makefile, I don’t actually see one in the directory. I do see:


But none of those contains the line “EXTRA_LIBS = […lots of libs here…]”

Any thoughts on that? Thanks again!

Makefile creation

Submitted by Pixel Chimp on Wed, 28/10/2009 - 05:38.

renbucholz, I’m not certain but I think the ./configure command creates it for you.

Check out the linked explanation, there is another suggestion to add the variable before the ./configure command. It could be worth a try.

Works for me

Submitted by kim.pepper@drup… on Mon, 09/11/2009 - 04:58.

Thanks so much. I tried various combinations of mysql, apache and PHP using mac ports, dmgs and compiling from source. If only I’d found this article first time around.



Submitted by Anonymous on Mon, 15/02/2010 - 08:56.

Great post, did the trick for me.


Submitted by Anonymous on Fri, 12/11/2010 - 20:56.

This post was really helpful, I used it two times in few days (due an OSX’s update), Thanks!

libjpg and libpng url are broken but it’s easy to get the new ones :)

Glad it helped…

Submitted by Pixel Chimp on Wed, 12/01/2011 - 18:55.

Sorry for the delay in publishing your comment,

Thanks for the library info, I think it is time to update with a new post.