May 6, 2013

Installing PHP 5.4+ from source on Mac OSX Mountain Lion

Download and extract the PHP source from, for me that was 5.4.14. Put it somewhere friendly, the desktop will do.

Open a terminal and install some dependancies via brew:

brew install libjpeg
brew install pcre
brew install libxml2
brew install mcrypt

Download and install ICU from

tar xzvf icu4c-4_8_1-src.tgz
cd icu/source
./runConfigureICU MacOSX
sudo make install

Rebuild IMAP, download source from

make osx EXTRACFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
sudo cp c-client/*.h /usr/local/include/
sudo cp c-client/*.c /usr/local/lib/
sudo cp c-client/c-client.a /usr/local/lib/libc-client.a

Then in the PHP source folder you downloaded:

cd ~/Desktop/php/ext/imap

Now run configure (I installed with pear):

./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  \
--with-iodbc=/usr  \
--with-ldap=/usr  \
--with-ldap-sasl=/usr  \
--with-libedit=/usr  \
--enable-mbstring  \
--enable-mbregex  \
--with-mysql=mysqlnd  \
--with-mysqli=mysqlnd  \
--with-pear  \
--with-pdo-mysql=mysqlnd  \
--with-mysql-sock=/var/mysql/mysql.sock  \
--with-readline=/usr  \
--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-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  \

If you want to check for errors in the build step you can run:

make test

This might take a while, like 30 mins.

If you’re feeling bold, or once the test has completed, run:

sudo make install


PS If you’re getting strange errors during configure make sure you have these libraries:

brew install libpng
brew install freetype
brew install openssl

Change install path

The notes above install in the default /usr folder. If you want to install in /opt instead (which is often cleaner), add this to the configure script:


Here’s a cutdown configure script I just used to install 5.4.15

'./configure'  '--prefix=/opt/php-5.4.15' '--with-libxml-dir=/usr' '--with-openssl=/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' '--enable-mbstring' '--enable-mbregex' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pear' '--with-pdo-mysql=mysqlnd' '--with-mysql-sock=/var/mysql/mysql.sock' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-tidy' '--with-xmlrpc' '--with-iconv-dir=/usr' '--with-xsl=/usr' '--enable-zip' '--enable-intl' '--with-pcre-regex' '--with-pgsql=/usr' '--with-pdo-pgsql=/usr' '--with-freetype-dir=/usr/X11' '--with-jpeg-dir=/usr' '--with-png-dir=/usr/X11' '--with-apxs2=/usr/sbin/apxs'

© Michael Sharman 2017