Wednesday, March 23, 2011

Setting up Wordpress on a Mac...

Was a pain in the ass!

Wordpress claims a 5 minute install. Maybe not for OSX users unfortunately. I unzipped the necessary wordpress files to my Sites directory with giddy anticipation. "This should be easy", I told myself. Simply navigate to/wp-admin/install.php and the rest is taken care of, right? Well, no. Turns out it isn't that easy. Running the install.php script initially rendered... nothing? Just a white page? Ugh, ok well now what?

After googling around a little bit it seems this is somewhat common, although I suspect it can be for a variety of different reasons. Without much to go on I decided to try debugging manually. Being new to wordpress and PHP in general caused me to spend the better part of my day inserting echo statements in the wordpress php to try and find the location of the error. I would have saved myself a lot of time if I'd realized WordPress has a DEBUG flag that is set to false by default! This flag is located in wp-config.php as WP_DEBUG.

Setting this to true output some very helpful information:

mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in wp-includes/wp-db.php

After googling a little bit more I discovered that this is a bug in MySQL and PHP. There is an error in the default php.ini file for some versions of OSX. PHP is attempting to connect to MySQL using the socket found at /var/mysql/mysql.sock but it doesn't exist there. It exists at /tmp/mysql.sock.

I was able to fix this by opening /etc/php.ini, going to the [MySQL] section and editing the offending line to read:

mysql.default_socket = /tmp/mysql.sock

After restarting the webserver WordPress installation worked like a charm.

Hopefully other enterprising Mac developers with WordPress trouble will find this post and save themselves the headache I endured.