Howto fix "PDOException: SQLSTATE[HY000] [2002] No such file or directory"

Sometimes everything works fine in the browser and then you want to make a job using CLI and get an error:

ERROR [User Error]: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory
IN GET dev/build
Line 159 in /path/to/framework/model/connect/PDOConnector.php

Looking at the _ss_environment.php we see:

<?php
 
/* What kind of environment is this: development, test, or live (ie, production)? */
define('SS_ENVIRONMENT_TYPE', 'dev');
 
// These four define set the database connection details.
define('SS_DATABASE_CLASS', 'MySQLPDODatabase');
define('SS_DATABASE_SERVER', 'localhost');

//...

Which should be fine.

Somehow it isn't. Webserver and CLI have different php.ini files and so different configurations, php doesn't seem to find the sock file or the current user has no permissions for that sock file... The number of possible bad configurations can be endless.

One pretty simple solution is to change define('SS_DATABASE_SERVER', 'localhost'); to define('SS_DATABASE_SERVER', '127.0.0.1');, so php connects over TCP/IP.

Rate this post

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments