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

亡梦爱人 提交于 2020-01-05 12:14:49

问题


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?


回答1:


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.




回答2:


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




回答3:


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!




回答4:


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


来源:https://stackoverflow.com/questions/5353954/installed-macports-php-now-cannot-interface-with-mysql-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!