MySQL DB connection error (localhost vs 127.0.0.1) after reboot when Jailkit is enabled

SYSTEM INFORMATION
OS type and version AlmaLinux 10.1 (Heliotrope Lion)
Webmin version 2.641
Virtualmin version 8.1.0.gpl-1
Webserver version Nginx 1.26.3
Related packages MariaDB 10.11.15 (mysql Ver 15.1)

When I enable Jailkit for a specific virtual server and then reboot the main server, any WordPress site installed on that virtual server loses its database connection, throwing the standard “Error establishing a database connection”.

Key Observations

  • The Error: WordPress is configured to connect to localhost. After a reboot, this fails.
  • The Workaround 1: If I change the WordPress configuration (wp-config.php) from localhost to 127.0.0.1, the connection works perfectly even after a reboot.
  • The Workaround 2: If I keep localhost, go to Virtualmin, disable Jailkit for that domain, and then reenable it, the localhost connection starts working again immediately (until the next server reboot).

Yes, that’s true.

A chroot jail severely restricts what the user has access to, and anything you haven’t explicitly put into the jail is not in the jail. (You’d need /etc/hosts, and maybe nsswitch.conf with files appearing first inside the jail.)

But, also, Mariadb may try to use a socket instead of the network port if not explicitly configured to use network. The socket obviously won’t be available in the jail. Using 127.0.0.1 forces a network connection, which can work inside the jail.