Adding PDO_MYSQL to Mac OS X Leopard Server
Like many dynamic libraries on OS X Server, PDO_MYSQL runs into complexity due to architecture considerations. Fortunately, it doesn’t have the added complexity of requiring lots of additional libraries. All you need is the appropriate version of MySQL.
Here’s the first error I received trying to use an existing compilation:
[toggle code]
- PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so' - (null) in Unknown on line 0
This is caused by an architecture mismatch: the file exists, but it doesn’t contain the code needed for your architecture. On our Leopard Server, that meant x86_64: the file contained only i386.
You can check the architecture(s) available in a file using the “file” command:
- $ file /usr/bin/php
- /usr/bin/php: Mach-O universal binary with 2 architectures
- /usr/bin/php (for architecture ppc7400): Mach-O executable ppc
- /usr/bin/php (for architecture i386): Mach-O executable i386
After I solved that, PHP had no trouble loading the library, and it appeared to work fine—except that query results using pdo_mysql produced garbage characters. This turned out to be because I had downloaded the file for MySQL 5.1, and our MySQL server uses 5.0. (This could mean things are going to suck when we upgrade the server from 5.0 to 5.1.)
So here are the steps I used to compile and install pdo_mysql:
- Download and install MySQL for Mac OS X 10.5 (x86_64)
- cd /usr/local/mysql/lib
- sudo ln -s . mysql
- cd
- Download PDO_MYSQL-1.0.2.tgz
- gunzip PDO_MYSQL-1.0.2.tgz
- tar -xvf PDO_MYSQL-1.0.2.tar
- cd PDO_MYSQL-1.0.2
- phpize
- LDFLAGS='-arch x86_64' ./configure --with-pdo-mysql=shared,/usr/local/mysql
- make
- sudo make install
- In /etc/php.ini, add “extension=pdo_mysql.so”. You might have to copy php.ini.default to php.ini first.
- In /etc/php.ini, add “extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20060613/"”.
If you have to play around with it, remember that you can use “phpize --clean” and “make clean” to clear out your old attempts.
Also, you can install DMG files using (for example, for installing MySQL 5.0.82):
- hdiutil attach mysql-5.0.82-osx10.5-x86_64.dmg
- cd /Volumes/mysql-5.0.82-osx10.5-x86_64/
- sudo installer -verbose -pkg mysql-5.0.82-osx10.5-x86_64.pkg -target /
- cd
- hdiutil detach mysql-5.0.82-osx10.5-x86_64/
Hopefully this will be unnecessary in Snow Leopard, though now that MySQL is managed by Oracle who knows what the default open source database will be by then.
Oh, and don’t forget that you have to have Xcode installed to compile software.
Updated August 12 2009 for extension_dir note.
- MySQL 5.0 Downloads
- “For users or organizations looking to maintain their own solutions.”
- PDO_MYSQL
- MySQL driver for PDO.
- Xcode
- This is the premiere programming package for Mac OS X, and it comes with every Mac. Xcode allows you to program in Objective C, C, C++, AppleScript, and Java. Groups are working on integrating other languages such as Python, Perl, Ada, and Pascal.
More Mac OS X Server
- checkpw failed, trying legacy method
- Tiger server does have auth_module available, it just isn’t listed in the httpd.conf file.
- No distutils? Install Xcode
- If Distutils is not available on Mac OS X Leopard, install the Xcode developer tools. Also, the upgrade process I followed for upgrading from Mailman 2.1.9 to 2.1.12.
- Installing OS X Server 10.5 from the command line
- I ran into some very odd trouble installing Mac OS X Server 10.5 (Leopard) on one of our G5 Xserves. So I attempted to use the command-line install to get the error message.
More MySQL
- MySQL for Other Applications
- The basics of working with MySQL for users of other applications such as Dreamweaver, PHP, Perl, or Python.
I crash and birn on the LDFLAGS... It does a lotof stuff in the log.. yes I have Xcode whatever that is.
tix at 12:41 a.m. July 4th, 2009
wiu4j
Obviously I can't really tell from that description, but if it has problems on the LDFLAGS line, make sure you're compiling it for your architecture? One way to find out what you need is to go into Activity Monitor and enable the "Kind" column; then look at the line(s) for httpd. PowerPC is ppc, PowerPC (64 bit) is ppc64. Intel is i386, and Intel (64 bit) is x86_64.
capvideo at 5:49 a.m. July 4th, 2009
tVAhq