Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to enable PDO_MYSQL in 5.2.4 PHP included into Leopard

I get it all working but getting an error:
uncaught exception 'PDOException' with message 'could not find driver'.

It looks like there is no PDO-MYSQL in phpinfo configuration list.

On dreamhost (and on my old tiger):
PDO support enabled
PDO drivers sqlite2, sqlite, mysql

pdo_mysql
PDO Driver for MySQL, client library version 5.0.16

on Leopard:
PDO
PDO support enabled
PDO drivers sqlite2, sqlite

Thanks,
V.

Mac OS X (10.5)

Posted on Oct 28, 2007 7:57 AM

Reply
Question marked as Best reply

Posted on Oct 30, 2007 10:52 AM

Hi,

I ran into this also. Oversight on behalf of Apple not to include MySQL PDO drivers. The quickest and dirtiest way I found to get past this is to install Marc Liyanage's PHP distribution for Apache 2. Out of the box this WON'T WORK. You have to move some files around.

1. Move Apple's php module out of the way.
sudo mv /usr/libexec/apache2/libphp5.so \
/usr/libexec/apache2/libphp5.so.bak

2. Move Marc's php module in.
sudo mv /usr/local/php5/libphp5.so \
/usr/libexec/apache2/libphp5.so

3. Create the following folder:
/usr/local/apache2/lib

4. Copy libexpat.0.dylib to the above folder.
This file comes as part of the Developer Tools (among other
things), so if you have Xcode installed, you should be able
to copy it from here:
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libexpat.0.dylib

5. Kick Apache
sudo apachectl configtest
sudo apachectl restart

Hope that works for you too.
Stew
17 replies
Question marked as Best reply

Oct 30, 2007 10:52 AM in response to ValGor

Hi,

I ran into this also. Oversight on behalf of Apple not to include MySQL PDO drivers. The quickest and dirtiest way I found to get past this is to install Marc Liyanage's PHP distribution for Apache 2. Out of the box this WON'T WORK. You have to move some files around.

1. Move Apple's php module out of the way.
sudo mv /usr/libexec/apache2/libphp5.so \
/usr/libexec/apache2/libphp5.so.bak

2. Move Marc's php module in.
sudo mv /usr/local/php5/libphp5.so \
/usr/libexec/apache2/libphp5.so

3. Create the following folder:
/usr/local/apache2/lib

4. Copy libexpat.0.dylib to the above folder.
This file comes as part of the Developer Tools (among other
things), so if you have Xcode installed, you should be able
to copy it from here:
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libexpat.0.dylib

5. Kick Apache
sudo apachectl configtest
sudo apachectl restart

Hope that works for you too.
Stew

Dec 28, 2007 2:42 PM in response to stewey

hi,

There are a lot of people who ran into this. So I was searching for a solution I saw this post and another on entropy.ch. When I try this solution Everything works and is loaded with the pdo_mysql driver. But the problem now is that when looking with phpinfo() the MYSQL_SOCKET is still on /tmp/mysql.sock. As I've found out this should be /var/mysql/mysql.sock.

When trying to connect with mysql with pdo I get an error
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock'

Does anybody know a solution for this.

Jan 25, 2008 7:37 AM in response to stewey

i got these errors when i switched them out...
bash-3.2# apachectl restart
bash-3.2# apachectl configtest
httpd: Syntax error on line 114 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/libphp5.so into server: dlopen(/usr/libexec/apache2/libphp5.so, 10): no suitable image found. Did find:\n\t/usr/libexec/apache2/libphp5.so: no matching architecture in universal wrapper
bash-3.2#

Apr 7, 2008 1:28 PM in response to elpepelucho

I'm having the exact same problem as you. As far as I can tell, the only way to enable PDO_MYSQL in PHP is by recompiling with appropriate configuration options.

Like you, I'm not sure how to do this and would appreciate a simple explanation of how to :

1) Locate the PHP binaries (I'm using PHP 5.2.5)
2) Do the unix stuff to recompile with the appropriate configuration options.

If anyone can help someone who is very rusty when it comes to unix I'd really appreciate it.

Apr 18, 2008 3:07 PM in response to ValGor

Is there a resolution to this without resorting to rebuilding PHP/Apache and Mysql. This is something that should be addressed with an update from apple allowing for the default versions of php etc to be used. I just got my mbp with the sole purpose of developing in PHP which is what I do for a living, so far its been no use (£1300 paper weight). Not being funny but it really is all it will be used for. I just spent seven hours looking for a solution to this problem and from what I can see a lot of other people have spent even longer. I must admit I'm gutted I cant use it, I look forward to getting a solution to this
I just hope it doesn't take too long. I use pdo_mysql and the gd extensions, I just migrated from windows which has an excellent php installer that allows extensions to be added and removed at will. This is what we need for the Mac.

May 31, 2008 1:06 AM in response to ValGor

I have managed to get PDO with MySQL support.

I installed the latest Marc Liyanage Beta from here:
http://www.entropy.ch/phpbb2/viewtopic.php?t=2945&sid=b820e5e830c0f1d8712f31b28b 832dc0

sudo mv /usr/local/php5 ~/Desktop/php5.old
curl -O http://www2.entropy.ch/download/php5-5.2.5-6-beta.tar.gz
tar -xzf php5-*-beta.tar.gz
sudo mv php5 /usr/local/
sudo chown -R root:admin /usr/local/php5
sudo ln -sf /usr/local/php5/entropy-php.conf /etc/apache2/other/+entropy-php.conf

then comment the existing php module in httpd.conf
#LoadModule php5_module libexec/apache2/libphp5.so
the entropy build adds a conf to 'other' if you install it as above, that loads the module from the /usr/local/php5 directory

(I did it this way so future upgrades are easier and the built in php remains untouched)

enable the php.ini in /usr/local/php5/lib/

edit the msyql socket connections there.
mysql.default_socket = /var/mysql/mysql.sock

(because I'd previously followed these instructions: http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-1 05/)


restart Apache

*watch out for short php tags* - they're disabled in this php build.

the final workaround I had to do for PDO to work properly was to include the socket in the connection string:
new PDO("mysql:host=localhost;dbname=test;unix socket=/path/to/socket/found_in_php.ini_ormy.cnf",'username','password');

I now have a working PHP installation with support for PDO and a bunch of other libraries on OSX 10.5.3 on a Mac Pro (2x2.66 Dual-Core)

Hope this helps someone (and I didn't leave out any steps)

May 31, 2008 7:02 AM in response to boldfysh

Further to the above - messing with the MySQl socket location is a bad idea.

better to leave it where it is (don't edit /etc/my.cnf) just edit the php.ini to point to where leopard wants its MySQL socket. /tmp/mysql.sock and then you won't have to worry about PDO_MYSQL not finding it, nor Perl modules etc.

see:
http://www.beyondmac.com/2007/10/30/php-mysql-on-leopard-mysqlsock-location/

Oct 10, 2008 5:14 PM in response to boldfysh

Hi there,

I had Apache2/PHP5 working just fine with Leopard, but needed the PDO_mysql extension so decided to give Marc's PHP5 module a try.

I tried the following steps but now my Apache2 server is totally dead. Won't even serve up a static image file 🙂 I'm wondering if it's because before running the installer, I didn't see the note about commenting out the line in my httpd.conf file which loads libphp5.so. However, I commented that line out AFTER running the installer, but it still didn't work. Also tried re-running the installer again after commenting that line out, but still no luck.

If I go back into my httpd.conf and uncomment the libphp5.so line, everything works fine with my old PHP5, but that doesn't really get me any farther ahead 🙂

Here are the steps I followed:

1. cd /usr/local
2. sudo curl -O http://www2.entropy.ch/download/entropy-php-5.2.4-1-apache2.tar.gz
3. sudo tar -xzf entropy-php-5.2.4-1-apache2.tar.gz
4. double-clicking entropy-php.mpkg and following the instructions

Marc's instructions seem to be for 10.4, so I'm wondering if I need to do anything special to get it to work on 10.5?

Thanks everyone!
Dave

How to enable PDO_MYSQL in 5.2.4 PHP included into Leopard

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.