Snow Leopard, Drupal, Macports and php

The short story is this: Snow Leopard has php 5.3.0 in, and although Drupal 6.14 now runs on that version, all previous drupal versions run on 5.2. [Solution? Manual compile - instructions below]

Mark Liyange’s php package has all of the nice stuff (like GD and mysql support) built into it, but it just doesn’t run with apache on Snow Leopard (white screen).

There’s no simple way to install php 5.2 without compiling it from source. Macports has a php52 package, but
sudo port install php52 yeilded a nasty error:

Undefined symbols:
“_res_9_dn_expand”, referenced from:
_zif_dns_get_mx in dns.o
“_res_9_search”, referenced from:
_zif_dns_get_mx in dns.o
_zif_dns_check_record in dns.o
“_res_9_dn_skipname”, referenced from:
_zif_dns_get_mx in dns.o
_zif_dns_get_mx in dns.o

Solution? Compile it manually and then run EXTRA_CFLAGS="-lresolv" make -j2

I did that, waited an hour, and it worked (hooray) except I had no mysql support. *sigh* I had to recompile with mysql, so…

Steps to compile php 5.2 on Snow Leopard with mysql support

Download php 5.2.11 source code or do it via macports by sudo port -v fetch php52

Uncompress it, open terminal and go to the uncompressed folder (macports stores the download in /opt/local/var/macports/distfiles/php5 (if you’ve already tried compiling with Macports, that’s where your download will be).

Configure the build by typing:

./configure '--prefix=/opt/local' '--mandir=/opt/local/share/man' '--infodir=/opt/local/share/info' '--with-config-file-path=/opt/local/etc/php5' '--with-config-file-scan-dir=/opt/local/var/db/php5' '--enable-calendar' '--with-iconv=/opt/local' '--enable-exif' '--enable-ftp' '--enable-wddx' '--with-zlib=/opt/local' '--with-bz2=/opt/local' '--with-mysql=/usr/local/mysql' '--with-mysql-sock=/tmp/mysql.sock' '--with-sqlite' '--without-pdo-sqlite' '--with-libxml-dir=/opt/local' '--with-gettext=/opt/local' '--with-libexpat-dir=/opt/local' '--with-xmlrpc' '--enable-soap' '--enable-bcmath' '--enable-mbstring' '--enable-dba' '--enable-zip' '--with-openssl=/opt/local' '--with-mhash=/opt/local' '--with-mcrypt=/opt/local' '--with-mime-magic' '--with-xsl=/opt/local' '--with-curl=/opt/local' '--with-pcre-regex=/opt/local' '--with-gd' '--with-jpeg-dir=/opt/local' '--with-png-dir=/opt/local' '--enable-gd-native-ttf' '--without-pear' '--with-freetype-dir=/opt/local' '--with-ldap=/usr' '--with-kerberos=/usr' '--with-iodbc=/usr' '--with-apxs2=/usr/sbin/apxs' '--with-mysqli=/usr/local/mysql/bin/mysql_config'

Notice the –with-mysql option, and the path to your mysql install (I used the binary from mysql.com so it’s in /usr/local/mysql – your folder will be different if you installed mysql with macports – same with –with-mysql-sock – mysql.com binary sticks it into /tmp/mysql.sock whereas macports puts it elsewhere – somewhere I can’t remember, but locate can help).

I also changed the –with-apxs2 option as it was pointing to my macports compile of apache2 which I’d decided not to use.

[You might wander, how did I get all of these options? After my first (successful) php 5.2 build (the one which didn't have mysql support), a phpinfo() shows the Configure Command used to configure from source. I copied that, and changed the relevant bits. And alas, found out too late I should've added mysqli support in, which is there now.]

Make the binaries with EXTRA_CFLAGS="-lresolv" make -j2
Copy to the right locations with a make install

If all goes well, your last step is to hook the php module into apache (php tries to do this itself, so just verify it worked). Open /private/etc/apache2/httpd.conf and search for “php”. That line should say:
LoadModule php5_module /usr/libexec/apache2/libphp5.so

Now just restart apache and you’re all done! No more drupal white screens, and now you can actually access your database. Whohoo.

Comments

  1. September 25th, 2009 | 9:03 pm

    For some reason my command line php binary wasn’t copied over the old one at /opt/local/bin/php – which meant drush didn’t work. Easy way to check – php -i and check the –with-mysql line (mine was “off”).

    I copied the new php binary from php-source-folder/sapi/cli

  2. September 25th, 2009 | 9:25 pm

    Some helpful tips from Installing PHP 5.2.10 on OS X 10.6 Snow Leopard if you’d like a similar version of getting this right.

Leave a reply