1

I had the standard version of PHP which comes bundled with Mac OS X working perfectly, but I wanted to upgrade to the new version so I used MacPorts, and all went well. I then edited my .conf file and checked and now my version of PHP is updated to the latest version.

However, upon running a PHP project I'm working on, it now seems I am unable to interface with MySQL which was working with the standard PHP install which came bundled with Mac OS X (note: I originally installed MySQL from their installer from their homepage).

My question is this: Is there a way to get MacPort PHP to work with my old MySQL installation?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Chris Russell
  • 11
  • 1
  • 2

4 Answers4

2

Have you installed the php5-mysql package from MacPorts?

The default installation of PHP in MacPorts is relatively minimal, but there are lots of add-on modules available.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
1

As noted by Alnitak in the comments, MacPorts 1.9.2 does not have a "mysql" variant. There is a way to work around it, nevertheless.

The php5-mysql port has a +mysql5 variant, but there is an even better way to solve to problem.

This is a great blog post http://top-frog.com/2009/08/26/macports-php5-mysql-mysqlnd/ which only states the same phrase that the php5-mysql post-install script does:

To use mysqlnd with a local MySQL server, edit /opt/local/etc/php5/php.ini and set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to /opt/local/var/run/mysql5/mysqld.sock

So if you're using MacOS X Server native MySQL server that socket would be easy to get by running ps ax | grep mysql. For me it was /var/mysql/mysql.sock.

And you could of course always change the socket in /etc/my.cnf

Vlad
  • 165
  • 5
0

In a moment of madness I worked it out.

Removed PHP from existence using MacPorts then reinstalled but this time added +mysql to the install.

Once this was done installed php5-mysql using MacPorts also. Then it worked!

Chris Russell
  • 11
  • 1
  • 2
  • strange - my install of MacPorts (v1.9.2) doesn't have a "+mysql" variant of PHP5. – Alnitak Mar 19 '11 at 10:54
  • you should check my comment out and everything will work out of the box, without having to install variants of ports. – Vlad Apr 14 '11 at 01:08
0

I also went to same problem with mysql and php5 installed. Luckily I am able to fix this by following Vlads advice; in a little different way. Note that port php5-mysql is NOT REQUIRED

Try /usr/bin/php -i|grep mysql|grep socket which results in

mysql.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock
mysqli.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock
pdo_mysql.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock

Note that php is pointing to wrong place; it should be /opt/local/var/run/mysql5/mysqld.sock

Solution:Create a symlink to correct path

sudo mkdir /var/mysql
sudo ln -s   /opt/local/var/run/mysql5/mysqld.sock  /var/mysql/mysql.sock
user602592
  • 117
  • 1
  • 10