Thursday, September 13, 2012

Compiling PHP 5.4.6 On OS X Mountain Lion

Mountain Lion came out, and still no PHP 5.4. It removed X11 though, which I used on Lion for the PNG and FreeType libraries when I compiled PHP 5.4 there. Instead of installing X11, I just compiled and installed the missing libraries this time. Command line tools have to be installed separately from inside XCode Preferences -> Downloads.

Here's how to install PHP 5.4.6 on Mountain Lion. I made a standalone installation, without affecting the Apache server that is already on the machine. PHP 5.4 has a built-in web server, so I don't need Apache on my laptop for development.

First, download, compile and install libjpeg. I downloaded it from, specifically the jpegsrc.v8d.tar.gz. Compile and install:

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

Download and install libfreetype from :

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

Download and install libpng from

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

Finally, configure, compile and install PHP:

./configure \ 
  --prefix=/usr/local/php546 \ 
  --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/local/libpng1512 \ 
  --with-freetype-dir=/usr/local/libfreetype2410 \ 
  --enable-gd-native-ttf \ 
  --with-ldap \ 
  --with-ldap-sasl \ 
  --enable-mbstring \ 
  --with-mysql \ 
  --with-pdo-mysql \ 
  --with-mysqli \ 
  --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 \ 

sudo make install

I also used pecl to install the MongoDB driver, but that made me realize that Mountain Lion did not have autoconf installed. So I downloaded it from, compiled and installed it:

./configure --prefix=/usr/local/autoconf269
sudo make install
sudo sh -c 'echo "/usr/local/autoconf269/bin" > /etc/paths.d/autoconf'

That last line adds this autoconf to the PATH for all users on the system, but you'll need to open a new Terminal to see it.

Then install the MongoDB driver:

sudo /usr/local/php546/bin/pecl install mongo
sudo sh -c 'echo "" >> /usr/local/php546/lib/php.ini'

No comments: