Wednesday, July 1, 2009

MySQL on OS X via PHP

I don't know why, but I always have trouble when I'm setting up PHP and MySQL on OS X. Actually, I do know why, and it's for two reasons:
  1. I usually forget that you have to uncomment the line 'Load module php5..." in /etc/apache2/httpd.conf
  2. Whenever I try to connect to mysql in php using localhost from a website I'm sandboxing on my machine, I get an error.
The error will read something like "Could not connect to socket via /var/mysql/mysl.sock..." I poked around and, indeed, there is no such path on my machine. Instead my mysql.sock goes to /temp/mysql.sock. If instead I try to change the host from 'localhost' to '/tmp/mysql.sock' then I get the same message, but after the server does a lot of thinking. I suspect that it may be something related to the file permissions on my system, but the only thing that works for me is to symlink to /tmp/mysql.sock in /var/mysql/mysql.sock. Bingo, problem solved. I'd be curious to know if there is a better workaround...

No comments: