Apache, PHP and MySQL on Mac OS X

Mac OS X has just been released and after compiling ssh, I went straight on to get Apache, PHP and MySQL working together. After a few tries I got it working fine. Here's how I did it:

Step 1: compiling Apache 1.3.19

Compiling apache proved to be very straightforward. You can find a good recipe at www.stepwise.com, Building Apache 1.3.19 for Mac OS X 1.0.

Step 2: compiling MySQL 3.23.35

I used the MySQL 3.23.35 source. This source needed a small bugfix (see below). Newer versions of MySQL (3.23.36 >) probably don't need the patch.

2.1: Fixing the source

I was quite disappointed that MySQL didn't compile straightforward. However,essentially I had to change only one line of code to have it compile flawlessly. The compile-time error occured on line 1232 in file mysqld.cc. My solution was to comment the DARWIN precompiler directives:

//#ifdef HAVE_DARWIN_THREADS
//    sa.sa_handler=( void (*)() ) handle_segfault;
//#else
    sa.sa_handler=handle_segfault;
//#endif
An other solution I found on the Internet that probably works equally well, but I haven't tried it myself:
#ifdef HAVE_DARWIN_THREADS
    sa.sa_handler=( void (*)(int) ) handle_segfault;   
#else
    sa.sa_handler=handle_segfault;
#endif
This minor change made mysql compile fine. However, later on I experienced problems with this build trying to use it with PHP. The problems seemed to be caused by the zlib-library that couldn't be loaded dynamically (undefined symbols _compress and _uncompress). Therefor, I decided to roll my own static zlib library, in stead of using Apple's shared library.

2.2: Compiling ZLib

I got a copy of zlib from freshmeat. This compiled just as expected (read the instructions). Install (being root!) placed zlib.a build in directory /usr/local/lib.

2.3: Compiling MySQL with a static zlib

I recompiled the fixed MySQL-source with the fresh static zlib library:

./configure --prefix=/usr/local/mysql --with-named-z-libs=/usr/local/libz.a
make
as root (su ...):
make install
Follow the instructions in the MySQL documentation to learn how to install the initial database.

Step 3: Compiling PHP

Compiling PHP can go wrong if you're on a HFS+ disc since it doesn't make a difference between upper and lowercase (unlike normal Unix filesystems like UFS). Since the only module that causes these compile-time problems is pear, which I don't need, so I just disabled it. The rest is straightfoward:

./configure --with-mysql=/usr/local/mysql --with-apxs --disable-pear
make
as root:
make install

The only thing you need to do after compiling and installing php is uncommenting the line

AddType application/x-httpd-php .php
in /etc/httpd/httpd.conf.
 

René Voorburg, March 29, 2001.