(NOTE: Make sure you read the comments for this post, as there's a better way to get around the 64-bit/32-bit problem without having to compile things. --Tom)
I don't know if I'm missing something big, but getting Perl, Apache, PHP, PDO and MySQL to play nice on my Mac OS X 10.5 install on my Intel Core 2 Duo (Penryn) MacBook Pro hasn't been easy. This is partly thanks to Apache being compiled with x86_64 support, and Perl with i386 only.
Anyway, Googling about, I notice that others have tried this arrangement with varying degrees of success. The easy answer is to install something like MAMP or replace the Apache and PHP installation with a custom build.
However, I prefer to keep my installation as stock as possible, and I'm not a huge fan of proprietary packaging systems like MacPorts and Fink. Don't get me wrong: those systems do what they're meant to do, and as a long-time FreeBSD user, I appreciate the approach. However, they don't fit into the Mac mindset too well, plus I'm too lazy to keep them up-to-date.
In other words, I want Apple to do it all for me, via Software Update where possible. The aim is to keep the stock Apache, PHP and Perl in place, and just add stuff.
The 10.5.3 Apache install does include PDO, but it's fairly crippled: the only drivers are the SQLite ones, even though standard "mysql" support is included. So, "pdo_mysql" will need to be installed... no problem: just install it as a module. But which architecture?
Since 10.5.3 Apache is compiled for i386 and x86_64, it'll run by default as 64-bit, requiring the 64-bit MySQL client libraries.
However, the included 10.5.3 Perl build is compiled only for i386, so if you want to build DBD::mysql for Perl as well, you'll need 32-bit MySQL client libraries.
The MySQL 5.1 official Leopard binary isn't currently a universal build, so right now if you download a binary distribution, you have to pick either 32-bit i386, or 64-bit x86_64. This will knacker either PHP/PDO (64-bit) or Perl/DBI (32-bit) So, assuming we don't want to replace -- or otherwise mess with -- the stock Apache, Perl and PHP, recompiling MySQL seems the way to go: we need to build a fat MySQL with both architectures.
To do this, download the MySQL source (I'm using 5.1.25), unzip and compile with something like:
MACOSX_DEPLOYMENT_TARGET=10.5 \ CFLAGS='-O3 -fno-common -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \ LDFLAGS='-O3 -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \ CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \ ./configure \ '--disable-dependency-tracking' \ '--prefix=/usr/local/mysql' \ '--localstatedir=/usr/local/mysql/data' \ '--libexecdir=/usr/local/mysql/bin' \ '--with-comment=MySQL Community Server (GPL)' \ '--enable-thread-safe-client' \ '--enable-local-infile' \ '--with-big-tables' make sudo make install
You'll then probably want to do something like:
sudo -s cd /usr/local export MYSQL_VERSION=mysql-`mysql/bin/mysql_config --version`-osx10.5-universal mv mysql $MYSQL_VERSION ln -s $MYSQL_VERSION mysql chown -R _mysql:staff $MYSQL_VERSION cd mysql ln -s share/mysql support-files ln -s var data bin/mysql_install_db --user=_mysql
I'm not sure whether this is the right procedure, but it works for me. A lot of this will change depending on your requirements and circumstances, so don't blame me if it kills your pets.
Next up is to install the PDO_mysql module. This is easy. Firstly, download the PHP source. As of Mac OS X 10.5.3, the current PHP is 5.2.5, but I downloaded 5.2.6 and it seemed fine. Unzip it, and go into the distribution directory (ie. php-5.2.6)
cd ext/pdo_mysql phpize MACOSX_DEPLOYMENT_TARGET=10.5 \ CFLAGS='-O3 -fno-common -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \ LDFLAGS='-O3 -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \ CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \ ./configure --prefix=/usr --with-pdo-mysql=/usr/local/mysql make sudo make install
You might need to add the following line to /etc/php.ini (creating that file, if necessary):
Then, restart Apache and you should have a working PDO_mysql driver.
Installing DBD::mysql for the stock Perl is a different matter. If you just do a CPAN install, then the multiple -arch tags that the mysql_config from your new Universal build of MySQL will return are going to foul it up. So instead, you can just build DBD::mysql for i386, as Perl is going to be running in 32-bit mode anyway.
There are probably better, easier ways of doing this, but I resorted to just doing a manual DBD::mysql build, stating the flags by hand:
perl Makefile.PL \ --cflags="-I/usr/local/mysql/include/mysql -Os -arch i386 -fno-common" \ --libs="-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm" make sudo make install
Anyway, if you can think of any improvements to the above routine, your comments are welcome.