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?

If only.

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 gd.so and 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
% [edit] /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.


These directions work great.

These directions work great. When I run a php -m from the command line, I can see pdo_mysql in the list, but if I check my phpinfo() page, I do not see pdo_mysql support. Any ideas?

Also, yes I have added the extension line to the php.ini file and I also restarted Apache, still does not show up in phpinfo().

Jim, I've seen this problem

Jim, I've seen this problem before, but since there are several possible causes, I'm not sure I can give you a sure fire solution.

Does your Apache PHP module perhaps use a separate php.ini file? Some configurations do this.

found your solution

After following directions above i too encountered the same problem (as long as your problem wasn't the location of extension_dir in your php.ini) i managed to solve it by simply recompiling apache (if unsure follow step by step) and it'll show mysql in the PDO and pdo_mysql in phpinfo() after starting up

hope this helps, and thanks for the help with installing the pdo for mysql


make sure web sharing is off

% curl -O http://ftp.wayne.edu/apache/httpd/httpd-2.2.11.tar.bz2
% tar xjf httpd-2.2.11.tar.bz2
% cd httpd-2.2.11
% ./configure --enable-layout=Darwin --enable-mods-shared=all
% make
% sudo make install

Unable to load dynamic library './pdo_mysql.so'

Many thanks for posting the instructions.

They ran through fine, but php -m produces this message:
PHP Warning: PHP Startup: Unable to load dynamic library './pdo_mysql.so' - (null) in Unknown on line 0
and no pdo_mysql in the list.

I wondered whether you have any ideas on this before I go for a more drastic solution.

Here are some PHP details:
PHP Version 5.2.8
System Darwin George-MacBook-Pro-2.local 9.7.0 Darwin Kernel Version 9.7.0: Tue Mar 31 22:52:17 PDT 2009; root:xnu-1228.12.14~1/RELEASE_I386 i386
Build Date Feb 5 2009 21:17:28


Change your extension_dir

In my php.ini i replaced:


and it worked a charm.