After jail upgrade "localhost" no longer works, only "127.0.0.1"...

For several years I have had a Freebsd 11.3 FAMP jail on a Truenas box for local website development (not a Truenas plugin, but a FAMP jail I created from scratch). A bunch of Wordpress sites sitting next to each other, accessible by the their respective directory paths sitting in the server root. When setting up Wordpress, using PhpMyAdmin or different plugins that need database access, I have always been able to use "localhost" when specifying database credentials.

Yesterday I upgraded the jail to 13.1 in one sweep and then ran pkg upgrade, mainly in order to upgrade php73 to php74. Since then I cannot use "localhost" anymore. I get errors saying cannot connect to database. I have had to change "localhost" to "127.0.0.1" when specifying credentials and then it works. For instance, in the wp-config.php that lives in each site's root folder and holds database credentials for the site in question. "localhost" always worked in that file but now I need to change it to "127.0.0.1" and then the site loads.

However, on the command line inside the jail I can successfully connect to mysql and view databases using mysql -h localhost -u root -p.

What might be causing this?

MariaDB was a point release upgrade from 10.4.12 to 10.4.26.
 
Check your /etc/hosts file.

And keep in mind that TrueNAS is not supported here.
 
Check your /etc/hosts file.

And keep in mind that TrueNAS is not supported here.

I did check the hosts file, and it seems to have been carried over from prior to the upgrade as my pfsense firewall line is still present.

Indeed, Truenas is not supported here, but I am operating under the impression that an iocage jail created from scratch in Truenas is essentially vanilla freebsd. I think that's what they say over at the Truenas forums.

Code:
root@webdev:~  # cat /etc/hosts
# $FreeBSD$
#
# Host Database
#
# This file should contain the addresses and aliases for local hosts that
# share this file.  Replace 'my.domain' below with the domainname of your
# machine.
#
::1            localhost localhost.my.domain
127.0.0.1        localhost localhost.my.domain webdev

# For pfsense - tell syslog where to find fafner
10.0.0.1        fafner
 
By Default MySQL listen only to the socket address. Check your my.cnf file and uncomment the bind-address or set it to localhost.

On FreeBSD the configuration is located at /usr/local/etc/mysql/my.cnf
I have no idea where is it on TrueNAS.

You can verify it via sockstat | grep mysql
 
I am operating under the impression that an iocage jail created from scratch in Truenas is essentially vanilla freebsd.
It's not. A jail runs on the host's kernel, which is a TrueNAS kernel.
 
By Default MySQL listen only to the socket address. Check your my.cnf file and uncomment the bind-address or set it to localhost.

On FreeBSD the configuration is located at /usr/local/etc/mysql/my.cnf
I have no idea where is it on TrueNAS.

You can verify it via sockstat | grep mysql

My my.cnf is very bare:
Code:
#
# This group is read both by the client and the server
# use it for options that affect everything, see
# https://mariadb.com/kb/en/configuring-mariadb-with-option-files/#option-groups
#
[client-server]
port    = 3306
socket  = /var/run/mysql/mysql.sock

#
# include *.cnf from the config directory
#
!includedir /usr/local/etc/mysql/conf.d/

So I looked at the includedir and in server.cnf I changed the existing already un-commented bind-address from 127.0.0.1 to localhost. When I do that mysql seems to switch to listening to IPv6. Could that could explain what is going on, because I have turned off IPv6 in my pfsense firewall? (a long time ago, for no real reason, but I left it off since I did not experience any problems).
EDIT: Actually my mistake, I had re-enabled IPv6 on the firewall already...


Code:
root@webdev:/usr/local/etc/mysql/conf.d  # sockstat | grep mysql
mysql    mysqld     78477 14 tcp6   ::1:3306              *:*
mysql    mysqld     78477 17 stream /var/run/mysql/mysql.sock

root@webdev:/usr/local/etc/mysql/conf.d  # cat /var/log/mysql/mysqld.err | grep socket
2022-11-29 21:35:41 0 [Note] Server socket created on IP: '127.0.0.1'.
Version: '10.4.26-MariaDB'  socket: '/var/run/mysql/mysql.sock'  port: 3306  FreeBSD Ports
2022-11-30 11:30:52 0 [Note] Server socket created on IP: '127.0.0.1'.
Version: '10.4.26-MariaDB'  socket: '/var/run/mysql/mysql.sock'  port: 3306  FreeBSD Ports
2022-11-30 11:52:13 0 [Note] Server socket created on IP: '::1'.
Version: '10.4.26-MariaDB'  socket: '/var/run/mysql/mysql.sock'  port: 3306  FreeBSD Ports
2022-11-30 12:09:08 0 [Note] Server socket created on IP: '::1'.
Version: '10.4.26-MariaDB'  socket: '/var/run/mysql/mysql.sock'  port: 3306  FreeBSD Ports
2022-11-30 12:14:59 0 [Note] Server socket created on IP: '127.0.0.1'.
Version: '10.4.26-MariaDB'  socket: '/var/run/mysql/mysql.sock'  port: 3306  FreeBSD Ports
2022-11-30 12:20:09 0 [Note] Server socket created on IP: '::1'.
 
Check your PHP mysqli.default_socket if it points to /var/run/mysql/mysql.sock

IF you are using PHP PDO by default it point to "/tmp/mysql.sock" and you can either change it my.cnf or in your php.ini.
pdo_mysql.default_socket"/tmp/mysql.sock"
 
Check your PHP mysqli.default_socket if it points to /var/run/mysql/mysql.sock

EUREKA !! 😃
It was empty.
So this was a PHP problem? That path was specified as socket in my.cnf, but PHP also needed the information?
(I went back to look at php.ini from before the upgrade, and under php73 the mysqli.default_socket field was also empty but it worked anyway.)

Thanks a zillion!!
 
That path was specified as socket in my.cnf
The location of that socket changed some time ago, PHP assumes the 'old' location; /tmp/mysql.sock.

Judging by your upgrade from PHP 7.3 to 7.4 I can only assume you're not updating your system very often. Great timing though, PHP 7.4 became EoL 2 days ago.

 
Judging by your upgrade from PHP 7.3 to 7.4 I can only assume you're not updating your system very often. Great timing though, PHP 7.4 became EoL 2 days ago.

:) I usually update when I begin a new project, and sometimes they are few and far in between. I am actually heading for 8.0, but I wanted to move one step at a time...
 
Back
Top