Not really sure how this happens but this is what solved it for me.
I ran the following php to show how mysql was configured for php:
<?php
// Display a list of PHP?s compile-time features
phpinfo();
?>
Under the mysql section you’ll see the following showing that PHP is looking for the socket under a /var dir by default:
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 4.1.22
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /var/mysql/mysql.sock
MYSQL_INCLUDE -I/usr/include/mysql
MYSQL_LIBS -L/usr/lib/mysql -lmysqlclient
You can also run the following to try to make a db connection through PHP and it will show the connection error which points to it looking for the mysql.sock file in the wrong directory.
<?php
if ($cn = mysql_connect("<host>", "<username>", "<password>")) {
echo "connected";
} else {
echo "not connected - " . mysql_error();
}
?>
To solve this I edited the php.ini file for my server and changed:
mysql.default_socket =
to
mysql.default_socket = /tmp/mysql.sock