Installing PHP 5.2.10 on OS X 10.6 Snow Leopard

Posted on Tue, 2009/09/08 - 10:38pm

Since my update to Snow Leopard, I was pleasantly surprised to find that Apple has updated PHP to version 5.3 and also included the GD extension. While I no longer have to rebuild the extension manually like on Leopard, these changes to PHP brought around a different problem: Drupal is currently not compatible with PHP 5.3 (#360605).

I've been trying to get my local Drupal installations working, and although the patch from post #84 works pretty well (when applied to a D6 CVS checkout), Ubercart is still nonfunctional. Since I am currently building and testing Ubercart-enabled sites, my only remaining option was to downgrade to PHP 5.2.10. I wanted to have the same extensions and options that Apple's PHP 5.3 build had, so I started by viewing the output of phpinfo() and copying the configure command. To compile PHP, locally installed copies of libpng, libjpeg and pcre are required so let's started with that:

(Like in the Leopard tutorial, I assume you have installed the Xcode & related developer utilities and that all downloads are saved in the "Downloads" folder in your home). Visit the libpng, libjpeg and PCRE homepages and download the latest release available for both. As of writing, the most recent releases are libjpeg 7, libpng 1.2.39 and PCRE 7.9.

The final step is to restart Apache - this can be done by toggling Web Sharing in System Preferences, or alternatively via the apachectl command:sudo apachectl restart

That's all! Now run phpinfo() and verify that PHP 5.2.10 is up & running. While I was trying to get this working, I stumbled accross two compile errors - for the sake of completeness, I've listed them below along with the failure cause:

This error occurs if EXTRA_CFLAGS="-lresolv" is not used while compiling PHP:

Comments

One problem I ran into with this was the php configure command didn't like paths starting with ~/Downloads. I just replaced every instance of ~/Downloads in the configure command with /Users/myusername/Downloads and it worked like a charm. Obviously replace "myusername" with your user name. Hope that helps someone. Otherwise, great tip! Glad to have PHP 5.2 running on Snow Leopard!!

The configuration command that is provided has some html in it which needs to be edited. There are a few instances of and which should be removed before running in the Terminal window. Easy to miss but necessary.

Which points did you have trouble with? Also, what is the error message that your machine displays when starting Apache? There should never be no PHP installed on your machine, since the procedure backs up the old php module. If something goes bad, just restore /usr/libexec/apache2/libphp5.so.orig106:mv /usr/libexec/apache2/libphp5.so.orig106 /usr/libexec/apache2/libphp5.so

Thank you very much for this helpful tutorial. It helped me to avoid using macports php52 port just to have php52 on SL for sake of my Drupal work.
One note for those trying to get php5.2 with latest pcre 8.0. It seems its directory struc was a bit different. The configure command for PHP step gives msg at end- 'couldn't locate pcre.h in ~/Downloads/pcre-8.0/usr/local'...So, i fell-back on 7.9..everything went like charm as mentioned in this article.

/Users/ys/Downloads/php-5.2.10/ext/mysqli/mysqli.c: In function ‘zm_startup_mysqli’:
/Users/ys/Downloads/php-5.2.10/ext/mysqli/mysqli.c:637: error: ‘MYSQL_RPL_MASTER’ undeclared (first use in this function)
/Users/ys/Downloads/php-5.2.10/ext/mysqli/mysqli.c:637: error: (Each undeclared identifier is reported only once
/Users/ys/Downloads/php-5.2.10/ext/mysqli/mysqli.c:637: error: for each function it appears in.)
/Users/ys/Downloads/php-5.2.10/ext/mysqli/mysqli.c:638: error: ‘MYSQL_RPL_SLAVE’ undeclared (first use in this function)
/Users/ys/Downloads/php-5.2.10/ext/mysqli/mysqli.c:639: error: ‘MYSQL_RPL_ADMIN’ undeclared (first use in this function)

... ...
enum mysql_protocol_type
{
MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
};
/*
There are three types of queries - the ones that have to go to
the master, the ones that go to a slave, and the adminstrative
type which must happen on the pivot connectioin
*/
enum mysql_rpl_type
{
MYSQL_RPL_MASTER, MYSQL_RPL_SLAVE, MYSQL_RPL_ADMIN
};

apparently, the source patch method to get libiconv to work is very hacky. It appears to be only working for PHP 5.2.10 source package. I have PHP 5.2.13, the line number of the below line is shifted and following the patch instruction here does NOT work!
#define iconv libiconv

As an alternative method, you should try to use MacPorts. (www.macports.org). Once it's installed, use port's variants to get PHP compiled with additional libraries.