Skip to content

Installing Custom PHP5 In Leopard

Categories: Apple, Web Development

Table of Contents

Lots of improvements have been made in Leopard, but the built in installation of PHP still lacks some essential packages and extensions (PDO, GD, etc). You could download MAMP or Marc’s package but either of those isn’t exactly a drop in replacement for the built in PHP installation – I’d rather not have two separate PHP installations floating around on my computer.

Below is a script to compile PHP as a drop in replacement. I didn’t come up with this completely on my own, these two sources were a great help. You’ll need to make sure you have MacPorts installed in order for the installation of additional modules using the script below to work. Make sure that MacPorts is configured to install all files into the /opt directory on your hard drive. The only downside to not using Marc’s package or MAMP is every time there is a system upgrade you’ll have to rerun this script.

[code lang=”bash”]

# you’ll have to aquire a new URL here: when a new version of PHP comes out
open php-5.2.6.tar.gz
cd php-5.2.6

# strip the 64 bit version of apache in order to eliminate compatibility issues with 32 bit PHP
sudo lipo /usr/sbin/httpd -thin i386 -output /usr/sbin/httpd

# install some modules
sudo port install libpng && sudo port install jpeg && sudo port install freetype && sudo port install gd2

# compile and install PHP
./configure –prefix=/usr –sysconfdir=/private/etc –with-config-file-path=/etc –mandir=/usr/share/man –infodir=/usr/share/info –with-apxs2=/usr/sbin/apxs –with-zlib-dir=/usr –with-mysql-sock=/var/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-pdo-dblib=/opt/local –with-mysql=/usr/local/mysql –with-pear –with-pdo-mysql=/usr/local/mysql/bin/mysql_config –enable-sockets –enable-dbx –enable-dbase –enable-trans-sid –enable-exif –enable-wddx –enable-ftp –enable-mbstring –enable-cli –enable-mbstring –enable-mbregex –enable-sockets –without-iconv –without-openssl –with-gd –with-curl –with-sqlite –with-jpeg-dir=/opt/local –with-gd=/opt/local –with-png-dir=/opt/local –with-freetype-dir=/opt/local && make && sudo make install

You will have to restart apache by toggling the “Web Sharing” checkbox off and on in the Sharing preferences. Hopefully this saves someone the headache it caused me 🙂

Quick side note. I’ve been looking for a good replacement for the clipboard history component of Quicksilver for awhile now and recently found Clyppan. I love it so far!