Saturday, March 31, 2012

Compiling PHP 5.4 on Mac OS X Lion

PHP 5.4 came out, but Apple hasn't updated Mac OS Lion with it yet:

$ php --version
PHP 5.3.8 with Suhosin-Patch (cli) (built: Nov 15 2011 15:33:15) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

To compile PHP 5.4, I had to download and install libjpeg first. I downloaded it from http://www.ijg.org/files/, specifically the jpegsrc.v8d.tar.gz. Comiplation and installation were easy:

./configure --prefix=/usr/local/libjpeg8d
make
sudo make install

After that I configured PHP with the following options:

./configure \
  --prefix=/usr/local/php540 \
  --with-apxs2=/usr/sbin/apxs \
  --with-openssl \
  --with-pcre-regex \
  --with-zlib \
  --enable-bcmath \
  --with-bz2 \
  --enable-calendar \
  --with-curl \
  --enable-exif \
  --enable-ftp \
  --with-gd \
  --with-jpeg-dir=/usr/local/libjpeg8d \
  --with-png-dir=/usr/X11 \
  --with-freetype-dir=/usr/X11 \
  --enable-gd-native-ttf \
  --with-ldap \
  --with-ldap-sasl \
  --enable-mbstring \
  --with-mysql \
  --with-pdo-mysql \
  --with-libedit \
  --enable-pcntl \
  --enable-shmop \
  --with-snmp \
  --enable-soap \
  --enable-sockets \
  --enable-sysvmsg \
  --enable-sysvsem \
  --enable-sysvshm \
  --with-tidy \
  --enable-wddx \
  --with-xmlrpc \
  --with-xsl \
  --enable-zip

Followed by:

make
make test

Some tests failed, a few of which already had bugs created for them. I sent the failed test report to PHP so they can debug the rest of them. The CLI binary works:

$ sapi/cli/php --version
PHP 5.4.0 (cli) (built: Mar 31 2012 14:49:14) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

Then finally installed PHP with:

sudo make install