After changing domain, Wordpress does not connect to database, user does, before the change, WP was working

OS type and version: CentOS Linux 7.9.2009
Webmin version: 1.981
Virtualmin version: 6.17
Related products version: Apache 2.4.6
Related products version: PHP 7.2.24
Related products version: Maria DB 5.5.68

  1. I changed the domain of a particular account for a new domain name. That worked fine, I tested with a test index.html file
  2. I changed the domain in wp_config.php

define(‘DOMAIN_CURRENT_SITE’, ‘’);

  1. I get Wordpress error:

Error establishing a database connection

Please note that before changing the domain, Wordpress was working fine.

  1. Tested the database user with this script, and is connecting fine to the database:
$link = mysqli_connect('localhost', 'user', 'password', "database");
if (!$link) {
die('connection error: ' . mysqli_error());
echo 'Success connection';
  1. I updated in table wp_options the registers: siteurl and home with the new domain URL using adminer

I initialized Bind, MariaDB, Apache and even restarted the server

  1. I followed this tutorial to the end, I did not repair the database, it was working fine before the domain change and I did not change anything in Wordpress.
    How to Fix the Error Establishing a Database Connection in WordPress

I do not know what else to do, I would suspect about Wordpress, but it was working fine just before changing the domain, and I only changed the domain for the new one, I left the same: administrator username, the home directory, and the user name suffix and group all are the same as in the old domain.

Any help is very much appreciated

You appear to have done everything right WRT configuration of WordPress. Try changing the database password of the virtual server via Virtualmin. Then apply the new password to the appropriate config files in WordPress.

Hopefully this shot in the dark will fix the issue.

1 Like

I’ve never seen that in a WP Config file and I’ve done well over a hundred Wordpress sites. Mine always have the setting for the database host and that’s always localhost.

WP Config doesn’t care about the domain name that I’ve ever seen.

Just for giggles, comment out that line completely and see what happens.

1 Like

Thank you for your time in answering @calport and @Gomez_Adams

  1. In wp-config.php I commented the line:
    /** define(‘DOMAIN_CURRENT_SITE’, ‘’); **/
    And when ran …:// it sent me to the old domain with the corresponding error not finding it.
    We can’t connect to the server at

  2. I created a new DB user and new random generated password, via Edit Databases in the Virtualmin account, while doing this I ran again: …:// and got this obvious error, because I had not changed yet the user in wp-config.php

Warning: mysqli_real_connect(): (HY000/1045): Access denied for user ‘originaluser’@‘localhost’ (using password: YES) in /home/account/public_html/wp-includes/wp-db.php on line 1653

Access denied for user 'originaluser'@'localhost' (using password: YES)

Error establishing a database connection

This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.

  • Are you sure you have the correct username and password?
  • Are you sure you have typed the correct hostname?
  • Are you sure the database server is running?

If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

  1. I changed the user and password for the new one created and I got, the same original one line error, with no more details:
    # Error establishing a database connection

I do not know what else to do, the problem is that this is was working before the change of domain name on the Virtualmin account.
Any more ideas are welcomed, thanks in advance.

Please note that all users and passwords I have tried are first tested with the above mentioned script, and all of them connect successfully to the wp database, and I was able to connect and make URL change to the wp database in table: wp_options using adminer

$link = mysqli_connect('localhost', 'user', 'password', "database");
if (!$link) {
die('connection error: ' . mysqli_error());
echo 'Success connection';

Thanks in advance for more ideas, regards

This is the content of the wp-config.php file I appreciate if someone can find an error:

 * The base configuration for WordPress
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 * This file contains the following configurations:
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * @link
 * @package WordPress

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'account_wordpress');

/** MySQL database username */
define('DB_USER', 'dbuser');

/** MySQL database password */
define('DB_PASSWORD', 'userpass');

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

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
define('WPLANG', 'es_ES');

 * Authentication Unique Keys and Salts.
 * Change these to different unique phrases!
 * You can generate these using the {@link secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 * @since 2.6.0
define('AUTH_KEY', 'qGtX3O11P8aSUvclem2QSGKdNYsDysobwt5fhlXZlvlpeuROSdV5GUbmufhHIpUV');
define('SECURE_AUTH_KEY', '3J6Tld8G1zlhADbLuagubGp7iWZVgv71ZYOk50HXRWZqnOmj55mJFCTrrwRGTMim');
define('LOGGED_IN_KEY', 'VXNwtnfighP2K0ZzE5LH6RAO2hIW78L0INr1Qy0DIuCSmZYzqkjPxwD84FfVbKvd');
define('NONCE_KEY', 'Sp7x5cyoLv4uVlxnX99fDXK04lWYFY6R1zFQhXCdTHvCFAN6zl8m2UR6AlXFtDB9');
define('AUTH_SALT', 'YrphircWuUErrAxiPQcoUlASrWCfJNNL2ApgQXPlGcl4VXu7ct6f2gJlMsUqSVcf');
define('SECURE_AUTH_SALT', 'YyoLvCc0t2BSmYOWP8ann9LkLWAcGCzQXRRE8dSZvlh1pm9Iw4nY8soAfKgnCwcD');
define('LOGGED_IN_SALT', 'kzTQoptGhXeSCrNHKBpa6CQyZW5XW3x0qo0EvLLr1WcGTst71PcuKdyUQFw6ebNt');
define('NONCE_SALT', '74VCe5lkNfYVA5g64WdqpEoKxhvbI0KWlGeK2CdJylo7I07qynphjRgEmwVmSpB6');


 * WordPress Database Table prefix.
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
$table_prefix = 'wp_';

 * For developers: WordPress debugging mode.
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 * @link
define( 'WP_DEBUG', true );
define( 'FS_METHOD', 'direct' );

define('WP_ALLOW_MULTISITE', true);

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', '');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);


/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';


I have no idea what all of that is or what it’s doing in your wp-config file. Again, over 100 Wordpress sites I’ve done over the years, I’ve never seen anything like that in a wp-config file.

If I’m correct? You should only had to of changed those lines.

1 Like

Hello and thanks to all.
It is a multisite website, and it was working fine before the change of the domain using Virtualmin, using all those parameters in the wp-config file.
Any more ideas?
Thanks and regards.

After the rename, check /etc/httpd/conf/httpd.conf to see if there are any ‘old’ entries of the domain and that new domain is what it says it is. For the individual domain -->services -->configure website → edit directives, may show correct entries after the rename but I would check the main apache config to see if something or some entries capturing old domain still.

That doesn’t make sense.

Were you using Virtualmin all along? If not, you need to explain what you really did. If you were on a different server and then just created a new server with Virtualmin then that’s going to cause a boatload of problems with multisite.

I think what he is trying to say is that it was working fine before the name change (same host/server). Wordpress, database, credentials etc fine as expected. When he renamed the domain to domain2, settings got out of sync and there is obviously some entries pointing to old domain name still.

1 Like

That’s what doesn’t make sense. In multisite, that’s not going to change the location of the database or anything else so it shouldn’t do that.

But a lot of what he’s saying makes it seem like he was hosting somewhere else, then set up a Virtualmin install, then that’s when everything went south.

Otherwise, why was he even messing with Bind, Apache and MariaDB to begin with? That would have all been running from the outset.

Guessing here that when you get frustrated - you would do anything rational or not :grinning:

1 Like

Sorry if I did not explain my self correct, English is not my native language. It is like you said @Whoops.

1. Originally I had: Virtualmin Original User (vminoriginaluser) working fine, with that wp-config.php file and database vminoriginaluser_wordpress with vminoriginaluser granted all tables to this database and its password.
1.1 I had ServerA with
1.2 VPS account: home/vminoriginaluser/
1.3 Domain:
1.4 WP Directory: home/vminoriginaluser/public_html/wp-content/ and the other wp directories
1.5 WP Database: vminoriginaluser_wordpress and vminoriginaluser and password
1.6 WP config file: home/vminoriginaluser/public_html/wp-config.php
1.7 WP installed: 5.7

  1. Then I made the change of for, only, I changed nothing else on the virtualmin account, I did it with vminoriginaluser in this menu:
    Virtualmin > > Server Configuration > Change Domain Name >
    New Domain Name:
    *Change Administration User Name: Leave as vminoriginaluser <selected
    *Change Home Directory: Leave as home/vminoriginaluser <selected
    *Change user name suffix and group: Leave as vminoriginaluser <selected

So I have now:
2.1 I have same ServerA with
2.2 Same VPS account: home/vminoriginaluser/
2.3 But New Domain:
2.4 Same WP Directory: home/vminoriginaluser/public_html/wp-content/ and the other wp directories
2.5 Same WP Database: vminoriginaluser_wordpress and same vminoriginaluser same password
2.6 Same WP config file: home/vminoriginaluser/public_html/wp-config.php
2.7 Same WP installed: 5.7

This is the contents of VirtualHost vminoriginaluser taken from apache httpd.conf file, I am not an expert in apache, I can not see how can this affect to WP database connection, please let me know if something is bad in these apache directives.

Thank you to all of you for your valuable time devoted to my problem, I appreciated, regards

<VirtualHost IP:80>
DocumentRoot /home/vminoriginaluser/public_html
ErrorLog /var/log/virtualmin/newdomain.com_error_log
CustomLog /var/log/virtualmin/newdomain.com_access_log combined
ScriptAlias /cgi-bin /home/vminoriginaluser/public_html/cgi-bin
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/vminoriginaluser/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
AddHandler fcgid-script .php5.6
AddHandler fcgid-script .php7.2
FCGIWrapper /home/vminoriginaluser/fcgi-bin/php7.2.fcgi .php
FCGIWrapper /home/vminoriginaluser/fcgi-bin/php5.fcgi .php5
FCGIWrapper /home/vminoriginaluser/fcgi-bin/php5.6.fcgi .php5.6
FCGIWrapper /home/vminoriginaluser/fcgi-bin/php7.2.fcgi .php7.2
<Directory /home/vminoriginaluser/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
RewriteEngine on
RewriteCond %{HTTP_HOST}
RewriteRule ^(.*) [R]
RewriteCond %{HTTP_HOST}
RewriteRule ^(.*) [R]
RemoveHandler .php
RemoveHandler .php5
RemoveHandler .php5.6
RemoveHandler .php7.2
php_admin_value engine Off
FcgidMaxRequestLen 1073741824
AuthName " statistics"
AuthType Basic
AuthUserFile /home/vminoriginaluser/.awstats-htpasswd
require valid-user
Redirect /mail/config-v1.1.xml /cgi-bin/autoconfig.cgi
Redirect /.well-known/autoconfig/mail/config-v1.1.xml /cgi-bin/autoconfig.cgi
IPCCommTimeout 31
php_value memory_limit 32M
php_value suhosin.session.encrypt Off

Could you post a link to the new domain so we can see what we see?

Well it could be as simple as going into MariaDB and making sure that the user has permission.

This only happens to me on a CentOS 7.9 server where I have to grant the user ALL and it will work fine from there.

Hello @cyberndt the administration user of the account is also the user of the database and it always had Database = ALL and I double-checked and it is correct. In fact, using Adminer with that user, I was able to change in table wp_options the registers: siteurl and home. The user can do anything with the database.

Hello @Gomez_Adams the error is very brief: Error establishing a database connection no more information, this is the capture:

I am posting the issue in Wordpress forum and I will wait for their response.

Thanks for all the nice answers and regards.

They’re going to ask the same thing. Caching is a huge issue and many people think they’ve cleared it when they haven’t. That’s why people ask for a link, to see if they get the same errors and if not which errors do they get.

It’s different about half the time, believe it or not.

Thank you for your kind help @Gomez_Adams I read in other web pages about the Cache issue in Wordpress and other CMSs, I disabled the cache via the config file. I have several Virtual Machines I checked with different Linux OS and browsers and a relative checked the website via her phone in another country and she got the same DB connection error.
Thanks and regards.