"SQLSTATE[HY000] [2002] No such file or directory" for compiled PHP
Par Mathieu le mardi 19 avril 2016, 22:52 - Hacks - Lien permanent
Let's say you connect to MySQL using "localhost"
Let's say you compiled PHP
Let's say you didn't specify the --with-mysql-sock= parameter in your configure command when you built mysql
And let's suppose you cannot connect to MySQL using PHP. CLI works fine, but not CGI.
Solution : fix the default sockets in php.ini (use your own working socket paths) :
pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock mysqli.default_socket = /var/run/mysqld/mysqld.sock # You shouldn't use mysql_ extension, but if you did: mysql.default_socket = /var/run/mysqld/mysqld.sock
I suppose that automatically converting "localhost" to an unix socket is done for performance reason on unix systems.