开发者

Installed MacPorts PHP, now cannot interface with MySQL - Mac OS X

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 a开发者_开发问答m 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?


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.


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


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!


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜