Compiling PHP5 DSO on Max OS X Leopard

Denver Timothy <denver at reduxcomputing dot com>
28 Oct 2007

Leopard by default uses Apache 2 and includes a PHP5 DSO that can be turned on by uncommenting one line in /etc/apache2/httpd.conf. The problem is that it does not support PostgreSQL (but it does support MySQL).

I thought that first I would see what would happen if I simply replaced the default DSO (found in /user/libexec/apache2/libphp5.so) with Marc Liyanage's DSO (if you install the package, it is found in /usr/local/php5).

$ sudo cp /usr/libexec/apache2/libphp5.so /usr/libexec/apache2/libphp5.so.orig
$ sudo cp /usr/local/php5/libphp5.so /usr/libexec/apache2/
$ sudo apachectl restart

That results in the following console message:

10/29/07 8:38:38 AM org.apache.httpd[7850] httpd: Syntax error on line 114 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/libphp5.so into server: dlopen(/usr/libexec/apache2/libphp5.so, 10): no suitable image found. Did find:\n\t/usr/libexec/apache2/libphp5.so: no matching architecture in universal wrapper

Well, let's see just what kind of file it is:

$ file /usr/local/php5/libphp5.so
libphp5.so: Mach-O universal binary with 2 architectures
libphp5.so (for architecture ppc): Mach-O bundle ppc
libphp5.so (for architecture i386): Mach-O bundle i386

That seems right, so maybe there's some issue with new Leopard stuff. So, I thought maybe I could roll my own DSO and see if I could fix that architecture problem. So, I downloaded the latest source from php.net. The version I am using at the moment is 5.2.4. For the moment, I'll just configure with the absolute minimum to avoid having to deal with any other libraries:

$ cd /Users/dlt
$ tar xvzf php-5.2.4.tar.gz
$ cd php-5.2.4
$ ./configure --prefix=/usr/local/php5 --with-apxs2
...
$ make
...
$ make install
...
/usr/share/httpd/build/instdso.sh SH_LIBTOOL='/usr/share/apr-1/build-1/libtool' libs/libphp5.so /usr/libexec/apache2
/usr/share/apr-1/build-1/libtool --mode=install cp libs/libphp5.so /usr/libexec/apache2/
cp libs/libphp5.so /usr/libexec/apache2/libphp5.so
Warning! dlname not found in /usr/libexec/apache2/libphp5.so.
Assuming installing a .so rather than a libtool archive.
chmod 755 /usr/libexec/apache2/libphp5.so
[activating module `php5' in /private/etc/apache2/httpd.conf]
...

OK, so doing a make install already puts the DSO in the right place. So, restarting apache again, results in this console message:

10/28/07 11:51:43 PM org.apache.httpd[66184] httpd: Syntax error on line 114 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/libphp5.so into server: dlopen(/usr/libexec/apache2/libphp5.so, 10): no suitable image found. Did find:\n\t/usr/libexec/apache2/libphp5.so: mach-o, but wrong architecture

Hmph. Well, as far as I know that should work. Maybe I'll try figuring out how to compile a universal binary. I doubt it'll make a difference, but I'm stuck at this point. I used the following to articles to attempt to compile for multiple architectures:

According to those articles, I modified Makefile in the PHP source tree. I changed CFLAGS_CLEAN and EXTRA_LDFLAGS as follows:

CFLAGS_CLEAN = -I/usr/include -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk
...
EXTRA_LDFLAGS = -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk

OK, lets try it again.

$ make clean
...
$ make
...
$ make install
...
/usr/share/httpd/build/instdso.sh SH_LIBTOOL='/usr/share/apr-1/build-1/libtool' libs/libphp5.so /usr/libexec/apache2
/usr/share/apr-1/build-1/libtool --mode=install cp libs/libphp5.so /usr/libexec/apache2/
cp libs/libphp5.so /usr/libexec/apache2/libphp5.so
Warning! dlname not found in /usr/libexec/apache2/libphp5.so.
Assuming installing a .so rather than a libtool archive.
chmod 755 /usr/libexec/apache2/libphp5.so
[activating module `php5' in /private/etc/apache2/httpd.conf]
...

Restarting apache again results in the following console message:

10/29/07 8:40:08 AM org.apache.httpd[7875] httpd: Syntax error on line 114 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/libphp5.so into server: dlopen(/usr/libexec/apache2/libphp5.so, 10): no suitable image found. Did find:\n\t/usr/libexec/apache2/libphp5.so: no matching architecture in universal wrapper

That's the same message as before. Is it the same kind of file as before? Yep, it is. Well, except this one is ppc7400, as opposed to just ppc.

$ file libs/libphp5.so
libphp5.so: Mach-O universal binary with 2 architectures
libs/libphp5.so (for architecture ppc7400): Mach-O bundle ppc
libs/libphp5.so (for architecture i386): Mach-O bundle i386

What am I missing?