Compiling latest version of PHP on Mac OS X


Mac OSX has a lot of Unix utilities, they’re very useful. You can start using many of your favorite Unix/Linux application out-of-the-box. But when it come to PHP, it’s not as good as PHP on Linux, What you have is an outdated version and you don’t have new features and performance of latest PHP .In this article, i’ll show you how to upgrade php on your Mac to latest version.

To find out current version of PHP, use this command :

$ 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 install PHP, you will need to install several other components like : libjpeg8d , libpng, freetype, openssl, libbcrypt.

you can install it all with Brew using these commands :

brew install libjpeg
brew install pcre
brew install libxml2
brew install mcrypt
brew install icu4c
brew link icu4c --force
brew install imap-uw

After that I configured PHP with the following options (apxs config apache to use this version of php, it’s importain):

./configure  \
--prefix=/usr  \
--mandir=/usr/share/man  \
--infodir=/usr/share/info  \
--sysconfdir=/private/etc  \
--with-apxs2=/usr/sbin/apxs  \
--enable-cli  \
--with-config-file-path=/etc  \
--with-libxml-dir=/usr  \
--with-openssl=/usr  \
--with-kerberos=/usr  \
--with-zlib=/usr  \
--enable-bcmath  \
--with-bz2=/usr  \
--enable-calendar  \
--with-curl=/usr  \
--enable-dba  \
--enable-exif  \
--enable-ftp  \
--with-gd  \
--enable-gd-native-ttf  \
--with-icu-dir=/usr/local/opt/icu4c  \
--with-iodbc=/usr  \
--with-ldap=/usr  \
--with-ldap-sasl=/usr  \
--with-libedit=/usr  \
--enable-mbstring  \
--enable-mbregex  \
--with-mysql=mysqlnd  \
--with-mysqli=mysqlnd  \
--without-pear  \
--with-pdo-mysql=mysqlnd  \
--with-mysql-sock=/tmp/mysql.sock  \
--with-readline=/usr  \
--enable-pcntl \
--enable-shmop  \
--with-snmp=/usr  \
--enable-soap  \
--enable-sockets  \
--enable-sysvmsg  \
--enable-sysvsem  \
--enable-sysvshm  \
--with-tidy  \
--enable-wddx  \
--with-xmlrpc  \
--with-iconv-dir=/usr  \
--with-mcrypt \
--with-xsl=/usr  \
--enable-zip  \
--with-imap=/usr/local/imap-2007 \
--with-kerberos \
--with-imap-ssl \
--enable-intl \
--with-pcre-regex  \
--with-pgsql=/usr  \
--with-pdo-pgsql=/usr \
--with-freetype-dir=/usr/X11 \
--with-jpeg-dir=/usr  \

Followed by:

make test

Some tests may failed, but it’s ok we have nothing to do with it. Finally, you can install PHP with:

sudo make install

To install other modules like intl, check out pecl to install it. This is my quick guide for system that already has PHP installed.

cd /usr/lib/php
sudo php install-pear-nozlib.phar

Edit/etc/php.ini and find the line: ;include_path = “.:/php/includes” and change it to:
include_path = “.:/usr/lib/php/pear”

Then, execute following commands to update & add new channels

sudo pear channel-update
sudo pecl channel-update
sudo pear upgrade-all
sudo pear channel-discover
sudo pear channel-discover
sudo pear channel-discover

From this point, you can install many other PHP utilities as you wish

sudo pear install phpunit/PHPUnit
sudo pear install phpunit/phpcpd
sudo pear install PHP_CodeSniffer
sudo pecl install apc
sudo pecl install intl
sudo pecl install xdebug

note: remember to follow output instruction after install each module from pecl or pear from console screen.