The Hero Dies in This One

Home, sweet home: blog.wombert.de

Compiling PHP 5.3 in 64-bit on OS X Leopard

Most tutorials out there about getting PHP 5.whatever installed compile their own 32-bit Apache, “slim” the OS X Apache2 fat binaries to 32 bit or use some other way of getting around the hassle of compiling as 64bit version.

That is, of course, very lame. We want to compile a 64 bit version of PHP, and we want to use the Apache2 that ships with Leopard.

However, Leopard also ships with horribly outdated versions of libxml2 (the very buggy 2.6.16) and libxslt. Also, it’s quite a hassle to get all the dependencies and libraries compiled by hand. So we cheat a little bit :)

  1. Download an entropy.ch Leopard package. Not officially out yet, so grab it from this forum thread (the latest release at this time is here).
  2. Extract it and move it where it belongs (/usr/local/php5).
  3. Download a PHP 5.3 snapshot and extract it somewhere.
  4. Copy the configure line from your entropy.ch release (e.g. via /usr/local/php5/bin/php -i | grep “Configure Command”).
  5. Change the path values of —prefix and —with-config-file-scan-dir to, say, “php5.3” instead of “php5”, and make sure that neither libxml nor libxsl paths are set to “shared”.
  6. Prepend CFLAGS=”-arch x86_64 -I/usr/local/php5/include/” LDFLAGS=”-L/usr/local/php5/include/” to the configure line, and add/change whatever else you want or not (I added —with-iconv for example). Also, I wasn’t able to compile in xmlreader support, so you might want to add —disable-xmlreader. My final configure command looked like this:
    CFLAGS=”-arch x86_64 -I/usr/local/php5/include/” LDFLAGS=”-L/usr/local/php5/include/” ‘./configure’ ‘—disable-dependency-tracking’ ‘—prefix=/usr/local/php5.3’ ‘—with-apxs2=/usr/sbin/apxs’ ‘—with-config-file-scan-dir=/usr/local/php5.3/php.d’ ‘—with-openssl=/usr’ ‘—with-zlib=/usr’ ‘—with-zlib-dir=/usr’ ‘—with-gd’ ‘—with-ldap’ ‘—with-xmlrpc’ ‘—enable-exif’ ‘—enable-soap’ ‘—enable-sqlite-utf8’ ‘—enable-wddx’ ‘—enable-ftp’ ‘—enable-sockets’ ‘—with-bz2=/usr’ ‘—enable-zip’ ‘—enable-pcntl’ ‘—enable-shmop’ ‘—enable-sysvsem’ ‘—enable-sysvshm’ ‘—enable-sysvmsg’ ‘—enable-memory-limit’ ‘—enable-mbstring’ ‘—enable-bcmath’ ‘—with-libxml-dir=/usr/local/php5’ ‘—with-xsl=/usr/local/php5’ ‘—with-gettext=/usr/local/php5’ ‘—with-curl=shared,/usr/local/php5’ ‘—with-png-dir=/usr/local/php5’ ‘—with-jpeg-dir=/usr/local/php5’ ‘—enable-gd-native-ttf’ ‘—with-freetype-dir=/usr/local/php5’ ‘—with-mysql=shared,/usr/local/php5’ ‘—with-mysqli=shared,/usr/local/php5/bin/mysql_config’ ‘—with-pdo-mysql=shared,/usr/local/php5’ ‘—with-pgsql=shared,/usr/local/php5’ ‘—with-pdo-pgsql=shared,/usr/local/php5’ ‘—with-mcrypt=shared,/usr/local/php5’ ‘—with-iconv’ —disable-xmlreader
  7. Run the configure.
  8. make
  9. install_name_tool -change /usr/lib/libxml2.2.dylib /usr/local/php5/lib/libxml2.2.dylib libs/libphp5.so
  10. install_name_tool -change /usr/lib/libxslt.1.dylib /usr/local/php5/lib/libxslt.1.dylib libs/libphp5.so
  11. install_name_tool -change /usr/lib/libexslt.0.dylib /usr/local/php5/lib/libexslt.0.dylib libs/libphp5.so
  12. Back up Apple’s libphp5.so, as it’s overwritten otherwise during install:
    sudo mv /usr/libexec/apache2/libphp5.so /usr/libexec/apache2/libphp5.so.leopard
  13. sudo make install
  14. Move the generated libphp5.so so our 5.3 is a completely “standalone” package:
    sudo mv /usr/libexec/apache2/libphp5.so /usr/local/php5.3/libphp5.so
  15. Restore the backup if you like:
    sudo cp /usr/libexec/apache2/libphp5.so.leopard /usr/libexec/apache2/libphp5.so
  16. Finally, your httpd.conf will need:
    LoadModule php5_module /usr/local/php5.3/libphp5.so
  17. Enjoy :)