PHP on 10.6

From ThinkyWiki

Revision as of 20:43, 4 December 2010 by Admin (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Running 10.5 Leopard?

This article is about reverting to PHP 5.2 on Snow Leopard. To install MAMP on Leopard you want MAMP!

The latest greatest PHP is always the best and most secure option for running a local webserver. Unfortunately not all popular content management systems are ready for PHP 5.3, which makes several changes to the language, extensions, and default settings. However it's pretty easy to go back to PHP 5.2 if you have all the necessary pieces. In general this follows the same procedure as building PHP in the MAMP setup, but preserves the previous version. Keep these components handy for a quick fix when PHP gets broken by a system or security update.

Needed Components

Before starting you will need the latest versions of these components:

* LIBPNG source with config -
* PCRE -
* PHP 5.2.x -


Before starting these might help (I needed them):

sudo mkdir /usr/local/include
sudo mkdir -p /usr/local/man/man1

Install libJPEG


Untar then proceed with the install:

cd jpeg-7
./configure --disable-shared --enable-static
make && sudo make install

Install libPNG

Get "Source with config script":

cd libpng-1.2.39
./configure --disable-shared --enable-static
make && sudo make install

Fix libiconv Support

The iconv.c file needs to be edited to get it compile on Snow Leopard:

cd php-5.2.11
joe ext/iconv/iconv.c

Find the following text:

#define iconv libiconv

Replace "libiconv" with "iconv" and save.

Preserve PHP 5.3

The PHP install writes over the PHP included with Mac OS X. If you want to restore PHP 5.3 later then now is the time to save it!

sudo mv /usr/libexec/apache2/ /usr/libexec/apache2/

Install PHP

Download at and find build help at

cd php-5.2.14
./configure \
--prefix=/usr \
--infodir=/usr/share/info \
--mandir=/usr/share/man \
--localstatedir=/var \
--enable-bcmath \
--enable-calendar \
--enable-cli \
--enable-exif \
--enable-fastcgi \
--enable-ftp \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-pdo \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-zip \
--sysconfdir=/private/etc \
--with-apxs2=/usr/sbin/apxs \
--with-bz2=/usr \
--with-config-file-path=/etc \
--with-curl=/usr \
--with-gd \
--with-iodbc=/usr \
--with-jpeg-dir=/usr/local \
--with-kerberos=/usr \
--with-ldap-sasl=/usr \
--with-ldap=/usr \
--with-libxml-dir=/usr \
--with-mysql-sock=/tmp/mysql.sock \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-openssl=/usr \
--with-pcre-regex=/usr/local \
--with-pdo-mysql=/usr/local/mysql/ \
--with-png-dir=/usr/local \
--with-snmp=/usr \
--with-xmlrpc \
--with-xsl=/usr \
--with-zlib=/usr \

EXTRA_CFLAGS="-lresolv" make -j2
sudo make install

Enable PHP 5.2.x in Apache

sudo apachectl restart

Check the Shell PATH

Make sure that /usr/local/bin comes before /usr/bin in the shell's $PATH variable by editing ~/.profile, otherwise the wrong version of PHP will be invoked by shell scripts. To find out which copy of PHP will be invoked on the command-line, just use:

which php

If you want to be more Draconian about it (for scripts that explicitly use #!/usr/bin/php) then make a soft link:

cd /usr/bin
sudo mv php php-orig
sudo ln -s /usr/local/bin/php php
Personal tools