Wordpress Error establishing DB if using "localhost"

[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.

I would expect this has to do with process isolation and filesystem / socket access.

the jail will prevent the daemons running as it’s own user from accessing certain sockets, like the mysql database socket. or the hosts file to resolve things like the hostname “localhost”

there may also be some things needed from things like /proc /sys /tmp and /dev
I wonder if in the error logs you can see things like access denied when you check for the errors in WordPress. might give a hint as to what resource is denied access. at the same time check the error logs for the global default websites, and the logs in /var/log/messages /var/log/secure.

1 Like

As a bit more explanation:

mysql used as localhost will connect via the actual file socket configured in the mysql server config. that action is denied by jailkit.

adding the path to the socket via say a mount --bind link into the jail causes risks as actually deleting the socket… can cause trouble. when one uses 127.0.0.1, it uses a tcp network socket, which is allowed and as a result the connection works.

the same goes for certain php-fpm options, if they use filesystem based sockets… jailkit acts up. run the worker pool on a TCP-listen port ( use the IP not the domain name localhost ) things start to work again.

As in the loopback test localhost is used by wordpress, the loopback test fails ( as wordpress is aware of ipv4 vs ipv6, and localhost working on both as resolved by the system itself then seems the proper way ) jailkit does act up.

2 Likes

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.