Wordpress Error establishing DB if using "localhost"

Hi, I have some sites, it used to run normally on virtualmin.

Suddenly, some of those are getting “error establishing database connection”

So I fix it to change this line in wp-config.php

/** MySQL hostname */
//define( 'DB_HOST', 'localhost' );
define( 'DB_HOST', '127.0.0.1' );
System hostname (127.0.0.1) Operating system AlmaLinux Linux 8.6
Webmin version 1.994 Usermin version 1.840
Virtualmin version 7.1 Authentic theme version 19.93.1
Perl version 5.026003
Path to Perl /usr/bin/perl
Python version 3.6.8
Path to Python /bin/python3
BIND version 9.11
Postfix version 3.5.8
Mail injection command /usr/lib/sendmail -t
Apache version 2.4.37
PHP versions 7.2.24, 7.4.30
Logrotate version 3.14.0
MariaDB version 10.3.32
ProFTPD version 1.36
SpamAssassin version 3.4.6

I kept as many settings as possible to be in default.
Things that are not in default settings are: install rclone, change apache server templates to enable http2, wordpress htaccess to apache conf, and php-fpm pool mode to ondemand.

How to fix localhost to be able to resolve, well, localhost on wordpress? I don’t know how to replicate. I have to fix it ASAP, but what can I do to catch the culprit when it happen again? What log should be monitored, or created to be able to find how to replicate this issue?


doing ping localhost on the VPS shows it’s ipv6 printed from ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 123.123.123.123  netmask 255.255.255.0  broadcast 111.111.111.111
        inet6 foo:7c54  prefixlen 64  scopeid 0x0<global> //this address is shown up when running ping localhost
        inet6 foo:7c54  prefixlen 64  scopeid 0x20<link>
        ether foo:54  txqueuelen 1000  (Ethernet)
1 Like

what do you have in Webmin-Network Configuration-Host Addresses?
You should see lines.

I don’t see localhost, but localhost4 and localhost6

That seems like the culprit. Will update soon if it is verified.

[root@vps public_html]# cat /etc/hosts

127.0.0.1  localhost localhost4 localhost4.localdomain4

::1  localhost localhost6 localhost6.localdomain6

It is not working yet…

@technicalw

Hi, firstly do you know the rules of the posting here? What os you run, what version of PHP, mariadb , Apache or nginx or fry pan it’s?

I don’t see anything like that on your initial pos, so do not expect someone to just guessing… people will usually considered this as spam at least me for sure.

@stefan1959

It’s not properly setup for production server… hostname, as usual, but who knows his settings and os, not possible to help as commands are different even for Alma or Ubuntu… if he is not bothering to tell, it’s fine :wink:

Hi, sorry for not providing enough information.

I have updated my initial post, but here are the server details from virtualmin dashboard. I hope it is suffice.

System hostname my.hostname.tld (127.0.0.1) Operating system AlmaLinux Linux 8.6
Webmin version 1.994 Usermin version 1.840
Virtualmin version 7.1 Authentic theme version 19.93.1
Perl version 5.026003
Path to Perl /usr/bin/perl
Python version 3.6.8
Path to Python /bin/python3
BIND version 9.11
Postfix version 3.5.8
Mail injection command /usr/lib/sendmail -t
Apache version 2.4.37
PHP versions 7.2.24, 7.4.30
Logrotate version 3.14.0
MariaDB version 10.3.32
ProFTPD version 1.36
SpamAssassin version 3.4.6

Virtualmin > System Settings > recheck configuration shows system ready to be used with virtualmin.

bump… Can anyone help?

@technicalw,

I can offer you tech support for a small fee. Let me know if you are interested.

1 Like

Look at your wp-config.php file and make sure that the database information matches the database you are using.

There are fields for database name, user, password, host, etc.

Make sure the info in that file matches the actual database, localhost, etc. that you’re using.

@technicalw thanks for the update.

I would like to apologize for being a bit harsh, but now it’s a bit more clear what the issue can be. I would go with Pete aka tnp… I know him more then decade and since I’m Linux guy (Debian) he is robust Unix man (centos rhel etc) and since Alma is very very close to centos my best bet would be his expertise. Obviously think twice when reading forums and make cut once

all matches. Just after some moments after creating virtual server (hours, days, weeks, random) those with define( 'DB_HOST', 'localhost' ); have “error establishing database connection” error.

I have tried to restart all services, reboot server, this issue is not reproduced.

@technicalw I can help you remote, what time would be suitable for you? I can slot you only in Friday,zoom or teams and TeamViewer here as I do not know you I would navigate you over the phone call. Also this iso off free support here and there to just make you going with virtual min

The problem is not reproduced yet since my session with @tpnsolutions 9 days ago, we both still didn’t able to identify the root problem. I hope that the problem is gone, but I can’t risk live site with define( 'DB_HOST', 'localhost' ); in that server.

All dummy virtual server, as subdomains, are still running well.

It looks like this thread explains the problem I am having here. We disabled jail and the problem is not showing up again.

Iliad, on Virtualmin staff, had initially recommended that I change “localhost” to “127.0.0.1” in the WordPress site’s wp-config.php file. I did that and the “jailed” sites affected worked fine.

I don’t pretend to know why or how this fixed it.

Most importantly, Ilian also said the Virtualmin fix to this would be forthcoming.

Thanks,
Charles

1 Like

This is my initial solution and it works. However, install scripts and most wordpress default configuration define db_host as localhost so that is another task for every wordpress install.

Be aware that I have curl problem too when it is jailed, and I cannot use any WP SMTP plugin to use gmail SMTP.
In the end, I disable every jails. But your configuration might differ with mine.

Thanks for the update. As of the time of this writing I have placed several more test websites on the Debian 10 box running Virtualmin 7.1 following this order:

  • create the SSL site on the domain
  • enable the jail
  • run the WordPress script

Each is using “localhost” and appear to be operating without error.

I’m just unable to enable the jail on a site that run the WordPress script on prior to enabling the jail.

I have not tried any SMTP plugins.

Thanks!
Charles

Chroot seem to cause a communication issue with WP.
Chroot jail domain Unix user set to NO.

Chroot jail domain Unix user set to YES.

But with it set to YES and change PHP to FCGld

No critical health issue.
It does say when using Chroot jail it apples to PHP FPM and FCGld but I have have no clue why it ok when using FCGld

This is interesting. maybe @Joe can explain the relevance, since virtualmin7 does not ship with FCGId pre-enabled.