# Wordpress Error establishing DB if using "localhost"

**URL:** <https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815>\
**Category:** Help! (Home for newbies)\
**Created:** [June 27, 2022, 5:20am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815 "2022-06-27T05:20:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![technicalw](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@technicalw](https://forum.virtualmin.com/u/technicalw)\
**Post date:** [June 27, 2022, 5:20am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/1 "2022-06-27T05:20:47Z")

</div>

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

```auto
/** MySQL hostname */
//define( 'DB_HOST', 'localhost' );
define( 'DB_HOST', '127.0.0.1' );

```

| **System hostname** | [(127.0.0.1)](https://127.0.0.1:10000/net/list_dns.cgi) | **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`

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![stefan1959](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/s/49beb7/32.png) [@stefan1959](https://forum.virtualmin.com/u/stefan1959)\
**Post date:** [June 27, 2022, 6:29am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/2 "2022-06-27T06:29:49Z")

</div>

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

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/3/338406716b8112f6a6c9ec3a23b50abf963e6734.png)

---

<div class="post-metadata">

**Author:** ![technicalw](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@technicalw](https://forum.virtualmin.com/u/technicalw)\
**Post date:** [June 27, 2022, 6:31am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/3 "2022-06-27T06:31:33Z")

</div>

I don’t see localhost, but `localhost4` and `localhost6`

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

---

<div class="post-metadata">

**Author:** ![technicalw](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@technicalw](https://forum.virtualmin.com/u/technicalw)\
**Post date:** [June 29, 2022, 8:13am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/4 "2022-06-29T08:13:14Z")

</div>

```auto
[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…

---

<div class="post-metadata">

**Author:** ![unborn](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/unborn/32/23353_2.png) [@unborn](https://forum.virtualmin.com/u/unborn)\
**Post date:** [June 29, 2022, 7:57pm UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/5 "2022-06-29T19:57:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unborn](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/unborn/32/23353_2.png) [@unborn](https://forum.virtualmin.com/u/unborn)\
**Post date:** [June 29, 2022, 8:01pm UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/6 "2022-06-29T20:01:42Z")

</div>

@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 😉

---

<div class="post-metadata">

**Author:** ![technicalw](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@technicalw](https://forum.virtualmin.com/u/technicalw)\
**Post date:** [June 30, 2022, 4:34am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/7 "2022-06-30T04:34:59Z")

</div>

Hi, sorry for not providing enough information.

> [@unborn](#):
>
> What os you run, what version of PHP, mariadb , Apache or nginx or fry pan it’s?

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)](https://127.0.0.1:10000/net/list_dns.cgi) | **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.

---

<div class="post-metadata">

**Author:** ![technicalw](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@technicalw](https://forum.virtualmin.com/u/technicalw)\
**Post date:** [July 6, 2022, 4:26am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/8 "2022-07-06T04:26:16Z")

</div>

bump… Can anyone help?

---

<div class="post-metadata">

**Author:** ![tpnsolutions](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/tpnsolutions/32/69_2.png) [@tpnsolutions](https://forum.virtualmin.com/u/tpnsolutions)\
**Post date:** [July 6, 2022, 8:46am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/9 "2022-07-06T08:46:34Z")

</div>

@technicalw,

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

---

<div class="post-metadata">

**Author:** ![Gomez\_Adams](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/gomez_adams/32/3221_2.png) [@Gomez\_Adams](https://forum.virtualmin.com/u/Gomez_Adams)\
**Post date:** [July 6, 2022, 11:55am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/10 "2022-07-06T11:55:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![unborn](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/unborn/32/23353_2.png) [@unborn](https://forum.virtualmin.com/u/unborn)\
**Post date:** [July 6, 2022, 5:42pm UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/11 "2022-07-06T17:42:20Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![technicalw](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@technicalw](https://forum.virtualmin.com/u/technicalw)\
**Post date:** [July 11, 2022, 7:02am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/12 "2022-07-11T07:02:04Z")

</div>

> [@Gomez\_Adams](#):
>
> Look at your wp-config.php file and make sure that the database information matches the database you are using.

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.

---

<div class="post-metadata">

**Author:** ![unborn](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/unborn/32/23353_2.png) [@unborn](https://forum.virtualmin.com/u/unborn)\
**Post date:** [July 13, 2022, 6:53pm UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/13 "2022-07-13T18:53:12Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![technicalw](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@technicalw](https://forum.virtualmin.com/u/technicalw)\
**Post date:** [July 15, 2022, 7:21am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/14 "2022-07-15T07:21:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![technicalw](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@technicalw](https://forum.virtualmin.com/u/technicalw)\
**Post date:** [July 25, 2022, 3:46am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/15 "2022-07-25T03:46:05Z")

</div>

> [@Activating jail breaks website database connection](https://forum.virtualmin.com/t/activating-jail-breaks-website-database-connection/116132):
>
> SYSTEM INFORMATION OS type and version Debian 10 Virtualmin version 7.1 I set up a website and used the WordPress script to install WordPress 6 (standalone as opposed to multisite). Before I enabled the jail, the Server Configuration \> PHP Options showed FPM selected and version 8.0.21 selected. Once I enabled the jail, if I go to [https://domain.tld/index.php](https://domain.tld/index.php) I get this rendered for a page (as opposed to the WordPress home page’s site): \<!DOCTYPE html\> \<html dir='ltr'\> \<head\> \<m…

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

---

<div class="post-metadata">

**Author:** ![charlesworks](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/charlesworks/32/5685_2.png) [@charlesworks](https://forum.virtualmin.com/u/charlesworks)\
**Post date:** [July 25, 2022, 11:23am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/16 "2022-07-25T11:23:11Z")

</div>

Ilia, 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, Ilia also said the Virtualmin fix to this would be forthcoming.

Thanks,  
Charles

---

<div class="post-metadata">

**Author:** ![technicalw](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@technicalw](https://forum.virtualmin.com/u/technicalw)\
**Post date:** [July 26, 2022, 2:44am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/17 "2022-07-26T02:44:44Z")

</div>

> [@charlesworks](#):
>
> change “localhost” to “127.0.0.1”

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.

---

<div class="post-metadata">

**Author:** ![charlesworks](https://cdn.forum.virtualmin.com/user_avatar/forum.virtualmin.com/charlesworks/32/5685_2.png) [@charlesworks](https://forum.virtualmin.com/u/charlesworks)\
**Post date:** [July 26, 2022, 4:18am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/18 "2022-07-26T04:18:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stefan1959](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/s/49beb7/32.png) [@stefan1959](https://forum.virtualmin.com/u/stefan1959)\
**Post date:** [July 26, 2022, 6:07am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/19 "2022-07-26T06:07:04Z")

</div>

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

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/4/42baa50961978ab4336a80e90f62eef8a501ae20.png)

Chroot jail domain Unix user set to YES.

 ![image](https://cdn.forum.virtualmin.com/uploads/default/original/2X/6/6fcf79507c00c2990c85dcdbc68deaa03daa61af.png)

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

---

<div class="post-metadata">

**Author:** ![technicalw](https://cdn.forum.virtualmin.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@technicalw](https://forum.virtualmin.com/u/technicalw)\
**Post date:** [July 27, 2022, 5:07am UTC](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815/20 "2022-07-27T05:07:06Z")

</div>

> [@stefan1959](#):
>
> 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.

[Next page](https://forum.virtualmin.com/t/wordpress-error-establishing-db-if-using-localhost/115815.md?page=2)
