Leopard PHP with MySQL PDO
Warning! This is a hack.
Mac OS X 10.5 Leopard ships with a pretty good version of PHP5 and an excellent version of Apache2. (It also ships with Ruby, Python and Perl.) Sounds like a decent FOSS development platform, doesn't it?
It's close, but not quite there, for my purposes and those of most developers I know. Why? No database.
Easily solved, you might say. Indeed, dropping a pre-packaged MySQL install into Leopard is easy and clean. But...
And you knew there had to be a catch, right? Else, why would I be writing this?
Leopard's PHP comes with the mysql and mysqli drivers compiled in. It also comes with the PDO interface and the pdo_sqlite driver compiled in. But no MySQL PDO driver. Which, if one is developing with PHP5, and especially if one is developing for Drupal 7, is a big problem.
After many hours of searching the web, it seemed like the most common solution was to download and install a pre-packaged binary PHP install, and use it instead of Apple's. I don't like cluttering up my filesystem, and I don't like overwriting vendor-supplied software since it makes updates risky. I've run into a couple of the shortcomings in Leopard's PHP before. I wanted to use GD and Xdebug, and they weren't available.
I had good luck compiling shared library (*.so) extensions for both GD and Xdebug, and simply dropping
xdebug.so into my
/usr/lib/php/extensions/no-debug-non-zts-20060613 directory. They just worked.
So I thought I'd try that again with the MySQL PDO driver. Unfortunately, it is no longer an extension post PHP 5.1, unlike the PECL extension available in PHP 5.0. Leopard runs PHP 5.2.
I did not want to compile my own PHP from scratch. It has some of the same problems as using downloaded packages and there are problems with compiling PHP 5 on Leopard for the x86_64 architecture.
On a whim, I download the old PECL extension for 5.0 and compiled it. I generated a
pdo_mysql.so and put it in my extensions directory, enabled it and it worked. At least so far. Since it's an old version, I may yet see some odd or buggy behavior. Time will tell.
In the meantime, if you want to try this, here are the steps:
% curl -O http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz % tar zxf PDO_MYSQL-1.0.2.tgz % cd PDO_MYSQL-1.0.2 % phpize % ./configure '--with-pdo-mysql=shared,/usr/local/mysql' % make % sudo cp modules/pdo_mysql.so /usr/lib/php/extensions/no-debug-no n-zts-20060613/ %  /etc/php.ini [insert] extension=pdo_mysql.so % php -m
A number of other people have encountered this problem, as well. The Drupal handbook has a page about it.