Installing PHP support for PostgreSQL on an OS X Leopard Server

OS X Leopard Server runs apache2 as a 64-bit application, which means that if you want to be able to run a PostgreSQL server that you can access from PHP web pages, PostgreSQL has to be built as a 64-bit binary, and PHP has to be re-built (with PostgreSQL) as a 64-bit binary as well. After some googling around, I started by using a script by Marc Liyanage for building a universal binary PostgreSQL. That was a good start, but didn't work on my Leopard server. What follows is a description of how I finally got it all to work.

Assumptions and Constraints

  1. Apple released Apache as a 64-bit application. I wanted not to change that, so installing a 32-bit version of Apache was out.
  2. UUID and LIBXML support needed to be built in order to build PostgreSQL. The Liyanage script included them, and I did not test trying to work without them.
  3. There was no reason for me to build a universal binary for postgres; the whole point of this project was to be compatible with Leopard's 64-bit Apache server.
  4. My server is an Intel box; no reason to build for PPC either. The compiler flag for generating 64-bit intel code is "-arch x86_64".
  5. I want to be able to upgrade the installation as new software versions are released, so I need parameterized scripts.

Hacking the Liyanage Script

I created a Makefile so I could build postgres with a make command instead of typing out the whole script name:

include ./Versions
default:
<tab>./liyanage.sh
clean:
<tab>sudo rm -fr libxml-install libxml2-${LIBXML_VERSION} \
ossp-uuid-install uuid-${UUID_VERSION} \
postgresql-${POSTGRESQL_VERSION}

The Versions file is there so that the Makefile and the script stay in sync when new versions come out:

POSTGRESQL_VERSION=8.3.3
LIBXML_VERSION=2.6.32
UUID_VERSION=1.6.2
JDBC_VERSION=8.3-603.jdbc4

The script itself is liyanage.sh. But be warned! (1) It makes liberal use of sudo commands (dangerous during development!) and (2) hasn’t been tested since editing some of the comments for posting here.
At this point I had a working PostgreSQL installation. Completing that required creating the postgres user, initializing the database, etc. The usual stuff.

Dealing with MySQL

Building PHP is complicated by the fact that Leopard does not come with the MySQL header files needed for the build (it's a MySQL thing, not an Applie thing. Google led me to a download site that took care of that. Building my own version of MySQL and installing it in /usr/local was not a good idea. Fortunately, the MySQL Makefile has an uninstall target.

Libraries

I built 64-bit versions of libjpeg, libpng, and zlib, and installed them all in /usr/local before building PHP. I put the configure and make commands in a script file for easy reuse, and then did a make test (99.5% tests passed) and sudo make install manually.

Comments

PHP Problems on September 12, 2009

Apparently, the security update that Apple did on September 12 installed an updated version of PHP, but one without Postgres support, of course. So I downloaded PHP 5.3.0 and tried to build it with my customized switches. It failed because it couldn't find libiconv.

This is quite distressing: my course fora (PHPBB2) and Academic Senate Database projects are currently totally broken until I get this fixed. Didn't I talk about the libiconv problem in the Git Saga?