Skip to navigation [a]

January 11, 2006

Fixing PHP-MySQL Connections In Mac OS X 10.4.4 //

Normally OS upgrades seem to go so smoothly… But this one left me (and I’m sure many others) with a nasty surprise — no communication between PHP and MySQL. Not nice. After a couple quick searches and no answers I decided to search out one myself. Discovering the problem was simple, and so apparently, was devising a solution.

If you fire up a quick PHP info file, you’ll see that the MySQL socket specified in the included version of PHP is wrong (or at least different and not what is expected) compared to older OS releases.

In 10.4.4, it is set as with-mysql-sock=/var/mysql/mysql.sock, whereas previously it was /tmp/mysql.sock.

Thankfully, there are at least two things you can do to remedy this.

  1. Locate and edit a php.ini file (by default it should be in the /etc directory and find the mysql.default_socket line and simply add /tmp/mysql.sock following the equals sign, save and restart Apache.
  2. In a plain text editor, create a new file in /etc/ named my.cnf. In the file, include a line which reads (on two lines):

[mysqld]
socket=/tmp/mysql.sock

Edit: The original second solution has been removed due to security concerns as indicated by Apple. A revised alternative solution has been added in its place.

So say you…

In the interest of completeness, on my own system rather than replacing the socket link I just have a blank space where “=/tmp/mysql.sock” should be. Just add that in and things will go fine.

Incidentally, you can use your favorite editor to make the change rather than having to learn vIm or something. Just use “open -a nameofeditor php.ini” and it will open up in TextWrangler or BBedit or whatever it is you use.

Chris Chris January 11, 2006

Right. True. BBEdit, TextWrangler and TextMate all include command-line tools that can make it simple to open files in the respective apps, so there is little or no need to learn vim, pico or vi.

For BBEdit it’s as simple as typing “bbedit /etc/php.ini”, and assuming the file exists, it will launch BBEdit and open the file for editing. Note you may need an administrator password before it lets you save any changes to a file.

Scott Scott January 11, 2006

Odd, Mine didn’t change a bit. MYSQL_SOCKET /tmp/mysql.sock

Any idea why that might have happened?

Jason Jason January 11, 2006

Jason - what did you do to check the MySQL socket? I did end up seeing another option for apparently fixing the connection problem today on MacFixit.com, but it didn’t seem as appealing to me.

Scott Scott January 11, 2006

I have a file on my PowerBook that is simply phpinfo(). I opened that and hunted for mysql where I found MYSQL_SOCKET /tmp/mysql.sock.

I had updated to 10.4.4 last night and I have not noticed anything worng with PHP/mySQL talking to each other.

Jason Jason January 11, 2006

You might want to check out this note from Apple: http://docs.info.apple.com/article.html?artnum=302977

sfn sfn January 14, 2006

Okay, I see now that the technote has been read… sorry.

sfn sfn January 14, 2006

sfn: Yeah, I saw that and updated the post to reflect the recommendations from Apple.

Scott Scott January 14, 2006

When you get to the bottom you go back to the top of the slide… or check out our B-sides

It’s all interconnected …On A Long Piece Of String

Feeds //

Get social and don’t be a lurker

Elsewhere // Click to view

01