I mentioned that I had a solution to the PHP and MySQL socket issue in my previous post but I figured it was worth a separate entry because it reminded me of a really nice feature of Unix that I had almost forgotten about – symbolic links.
The original problem occurred because PHP (through Apache) was trying to connect to a file in a certain location (/var/mysql/mysql.sock) and it didn’t exist there, it existed in another place (/tmp/mysql.sock). The solution? Create a virtual link between 2 locations on disk.
ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Now that these 2 ‘files’ are linked, any information that flows through /tmp/mysql.sock will automatically appear as if it is flowing through /var/mysql/mysql.sock as well.
The great thing about this solution is that it focused not around changing either application to look in an alternative place but instead to use the power of the operarting system to trick them both into being happy by creating a virtual link between the two locations. The biggest benefit of this is that any application that was already installed that was depending on MySQL existing at /tmp/mysql.sock will still work without any modification.
I really do love that Mac OS X is based on BSD, it was a great decision.