0

Feel free to migrate this. Its ambiguous to me if it belongs in serverfault, stackoverflow, or Unix & Linux.

I recently deployed a handful of wordpress sites for a client. I started to notice the following error in the error logs.

FastCGI: server "/usr/lib/cgi-bin/php5-fpm.fcgi" stderr: PHP message: PHP Warning:  mysqli_real_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/website_user/website/wp-includes/wp-db.php on line 1490

The problem is that MySQL is running on /var/lib/mysql/mysql.sock but mysqli_real_connect() is trying to connect on /var/run/mysqld/mysqld.sock.

Yes I am painfully aware that running mysql on a non-default socket is dumb and just asking for a headache. At this point though that path has been changed in more places than I can remember so changing it back would also be a pain.

# php5-fpm --version
PHP 5.5.9-1ubuntu4.14 (fpm-fcgi) (built: Oct 28 2015 01:38:24)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

#php5-fpm --info | grep .default_socket
mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
mysqli.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
pdo_mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock

When I view phpinfo() from a web browser I notice

MYSQLI_SOCKET = /var/run/mysqld/mysqld.sock 
mysqli.default_socket = /var/lib/mysql/mysql.sock

enter image description here

Am I missing a directive in php.ini that will set MYSQLI_SOCKET? Is it a bug that its not using mysqli.default_socket?

I believe I have worked around the issue by granting the user permission to connect to MySQL on 127.0.0.1 and changing DB_HOST in wordpress to be 127.0.0.1:3306. So far I have not seen any more errors show up in the error log.

I'm not sure what this code does since the web page appears to be fine and we have had no complaints from the client in the couple weeks its been live.

I still would like to know what the proper fix is. Why php5-fpm is ignoring mysqli.default_socket or if there is another directive I should be using instead.

I found several php bugs that are similar to this problem but they are all very old and all seem to be closed as having been fixed.

This is being hosted on Apache with php5-fpm and MySQL. This is not our normal hosting stack (we normally develop Django sites for our clients). So I could just be making a novice mistake.

digitaladdictions
  • 1,505
  • 1
  • 12
  • 30
  • The phpinfo in the web browser probably also shows which php.ini file is used and where you still/also need to update the `mysqli.default_socket` setting – HBruijn Apr 13 '16 at 05:39
  • There is only one php.ini on the system. I confirmed its the one shown by phpinfo() in the web browser. Also the screenshot clearly shows the change I made in the php.ini. There are two different sockets being referenced in the same mysqli section. – digitaladdictions Apr 13 '16 at 05:42

0 Answers0