Tuesday, March 17, 2009
php 5.2.9 + mysql + pdo_mysql on leopard
** Click here for PHP 5.3.0 **
This is a brief explanation of how you might be able to get pdo_mysql working on Leopard (OS X 10.5.6 and 10.5.7) with the stock Apache installation, on a Core 2 based Mac, while conveniently updating PHP as well. I was able to scrape this together from a few blog posts, mostly this one, and also some guess work.
This installation only covers 64-bit capable Intel Macs: those with the Core 2 processor. I might be able to guess at 32-bit (original Core) instructions; comment here if you need them.
1. Make a backup copy of this file: /usr/libexec/apache2/libphp5.so
2. Download and install MySQL from the MySQL website. Make sure to download the x86_64 package.
3. Download and unzip the PHP source code from the PHP website. I used the latest, PHP 5.2.9, at the time of this writing.
4. Open a terminal window and move to the unzipped directory, then execute the following commands.
CFLAGS='-O2 -arch x86_64' \
LDFLAGS='-O2 -arch x86_64' \
CXXFLAGS='-O2 -arch x86_64' \
./configure '--prefix=/usr/local/php-5.2.9' \
'--with-openssl' '--with-xmlrpc' \
sudo make install
sudo apachectl restart
Take a look at your phpinfo(), and if all went well, you will see MySQL listed in the drivers under PDO. If it doesn't work, the bailout is to put the original libphp5.so back into place... you know, the one you backed up in step 1... you did back it up, right?
PHP CLI users: If you are getting this warning:
PHP Warning: PHP Startup: Unable to load dynamic library './pdo_mysql.so' - (null) in Unknown on line 0
Comment out the following line in /etc/php.ini: