When using the staging feature in the Webfort control panel, some WordPress sites may display the following error:
"Error establishing a database connection"
This can happen because the staging site's wp-config.php file still contains the original database credentials from the live site, which don't match the staging database. Follow the steps below to fix it.
How to Fix It
- In the Webfort control panel, navigate to your staged website.
- Go to Databases, then click Users and make a note of the database username shown.
- Go to Files > public_html and locate wp-config.php.
- Click the three-dot menu next to the file and select Edit.
- Update the following two lines to match the username from step 2:
DB_NAMEDB_USER
- Save the file.
Example
Before:
define( 'DB_NAME', 'test_test_example_wp307' );
define( 'DB_USER', 'test_test_example_wp307' );
After:
define( 'DB_NAME', 'test_example_wp307' );
define( 'DB_USER', 'test_example_wp307' );
Note: This issue is rare and only affects certain WordPress sites that were migrated from older cPanel environments. Most staging setups work without any changes needed.
If you're unsure what changes to make or the issue persists, contact our support team and we'll help get it sorted.