Upgrading and Beefing Up PHP on Mac OS X Server

—by David O’Donnell, atropos@afp548.com

16 April 2003—Updated 5 May 2003

If you’re a Web-head (and these days, who isn't?) then you’ve probably dabbled at least a little in PHP, a “hypertext preprocessor” language that lets you turn plain old Web pages into dynamic, interactive powerhouses. In this article, you will replace the version of PHP Apple ships with Mac OS X 10.2.x—PHP 4.1.2—with the latest-and-greatest release from PHP’s creators: PHP 4.3.1. In the process, you’ll beef up PHP with support for MySQL, LDAP, the GD library, TIFF support, and enable the command line functionality as well.

Before we get started, I want to give nods of thanks to the folks at PHPMac.com and to Marc Liyange. Their guidance made this article possible.

(1) Use the Source, Luke!

Before we install anything, we need to obtain the source files. There are four parts we need to get: PHP, LibJPEG, LibPNG, and LibTIFF. Navigate to your favourite source files directory (one with a path with no spaces in its name!) and retrieve the following:

curl -O ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
curl -O http://www.libpng.org/pub/png/src/libpng-1.2.5.tar.gz
curl -O ftp://ftp.remotesensing.org/pub/libtiff/tiff-v3.5.7.tar.gz

The PHP source is available from PHP’s Web site (http://www.php.net/get/php-4.3.1.tar.gz/from/a/mirror); please use a mirror site that is physically closest to you. After you retrieve the sources, run them through gnutar zxf to decompress them into their appropriate directories.

For those curious, we’re not bothering to get the GD source; the PHP developers have included a version in the 2.0 distribution tree, and it compiles just fine under Mac OS X Server. If you want to be daring, you can get the latest version (2.0.12 as of 29 March 2003) from Boutell.com. If you give it a try and experience no problems, please let me know!

(2) LibJPEG

The first library we’re going to compile and install is LibJPEG. This library enables the GD library to manipulate JPEG-encoded images. We’re also going to setup a few directories that may, or may not, already exist. The process is pretty painless:

cd jpeg-6b
./configure

Mac OS X wants to put man pages in /usr/share/man, so unless you’ve already symlinked /usr/local/man to /usr/share/man, edit the Makefile and change the line mandir = $(prefix)/man/man$(manext) to mandir = /usr/share/man/man$(manext). Note that we’re not using the --prefix option on ./configure because we’re fine with the rest of the files going into /usr/local/.

make
sudo mkdir -p /usr/local/include
sudo mkdir -p /usr/local/bin
sudo mkdir -p /usr/local/lib
sudo mkdir -p /usr/local/man
sudo make install
sudo make install-lib
sudo ranlib /usr/local/lib/libjpeg.a
cd ..

(2) LibPNG

This next library lets GD work with images that are PNG (Portable Network Graphics)-encoded. PNG is a lossless compression-based format that can be considered the successor to GIF in the same fashion that IMAP is the successor to POP in the e-mail world. PNG images can be encoded in 8- or 24-bit color and can contain transparency information. Unfortunately, support for PNG images is spotty at best in Micorsoft’s browsers. Mac users have the best support, though it is hardly as good as in Safari, OmniWeb, Chimera, Netscape, Mozilla, and so forth.

In any event, the steps involved in compiling and installing LibPNG are also fairly simple:

cd libpng-1.2.5
cp scripts/makefile.macosx ./Makefile

In the Makefile, make the following changes:

make
sudo make install
sudo ranlib /usr/local/lib/libpng.a
cd ..

(3) LibTIFF

LibTIFF adds TIFF image support to PHP. It’s unclear whether it interfaces with GD or not, but it was quick and easy to compile and install—so why not...

cd tiff-v3.5.7
./configure

You’ll see a list of parameters. Make the following changes to them:

make
sudo make install
sudo ranlib /usr/local/lib/libtiff.a
cd ..

(4) Le grande finale: PHP itself

Now we will compile and install PHP itself. After changing to the php-4.3.1 directory, you need to make one important change to the configure file to support Apple’s dylib installation of OpenLDAP. To do so, open the file in a command-line text editor (I like emacs) and search for the phrase “libldap.so.3"; change it to “libldap.dylib” and save the file.

Next, we configure the software. This will take a few minutes to complete:

./configure --with-xml \
--with-zlib \
--with-gd \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--with-tiff-dir=/usr/local \
--with-mysql \
--with-apxs=/usr/sbin/apxs \
--with-ldap \
--enable-ftp
--enable-cli

Don’t be alarmed if you see any errors, unless they break the configuration process. You can always re-run the command after fixing whatever’s broken (for example, if you don’t have MySQL configured). Next up, you will make and install the software. Feel free to grab a snack or beverage during the make process, as it is pretty lengthy.

Note: Now would be a good time to make a backup of your existing libphp4.so file (it’s at /usr/libexec/httpd/libphp4.so) just in case something goes unexpectedly wrong with the build-and-install process.

2003-04-20: One of our readers reported losing databases kept in /var/mysql after installing PHP 4.3.1. If your MySQL creates its databases there, please back them up prior to running the following commands.

make
sudo make install
sudo apachectl graceful

If you don’t already have an info.php page, create one in /Library/WebServer/Documents that contains the following line:

<?php phpinfo(); ?>

then navigate to it, enjoy the results, and start playing with more PHP!

Resources:

PHP Web site: http://www.php.net/
PHPMac Web site: http://www.phpmac.com/
Marc Liyange’s Mac OS X Software: http://www.entropy.ch/software/macosx/
PNG (Portable Network Graphics) Web site: http://www.libpng.org/pub/png/
Boutell.com GD Web site: http://www.boutell.com/gd/