Skip to content

Solutions for common WordPress problems

Fix error establishing a database connection

The most common causes of “error establishing a database connection” are:

  1. MySQL is not running because the server’s disk is full.
  2. MySQL is not running because the server ran out of memory.
  3. The database credentials in the wp-config.php file are incorrect.

Check if MySQL is running

SSH into your server as root and run the following command to check if MySQL is running.

Terminal window
sudo service mysql status

If MySQL is not running, use the following command to check the server’s disk space.

Terminal window
sudo df -h /

Next, check the MySQL service logs for errors.

Check database credentials

If MySQL is running, the “error establishing a database connection” problem is likely due to incorrect MySQL credentials in the app’s wp-config.php file.

To ensure the database credentials in the wp-config.php are correct, update the database user’s password to the value of DB_PASSWORD in the app’s wp-config.php file.

Fix WordPress redirecting to the wrong domain

To fix WordPress redirecting to the wrong domain, change the configured WordPress address and Site address.

There are three ways to change the WordPress URL:

  1. Through the command line using WP-CLI.
  2. Through the WordPress dashboard (wp-admin).
  3. Through the wp-config.php file.

Change the WordPress URL using WP-CLI

SSH into the server as the app’s system user and change directory to the app’s public/ directory.

Terminal window
cd ~/apps/APPNAME/public./

Next, use the wp option update command to change the WordPress URL.

Terminal window
wp option update home 'https://example.com'
wp option update siteurl 'https://example.com'

Learn more about using WP-CLI.

Change the WordPress URL through wp-admin

If you can log into the WordPress dashboard, use the following steps.

  1. Log into the WordPress dashboard.
  2. Click on Settings.
  3. Update the WordPress address and Site address.
  4. Save your changes.

Change the WordPress URL through wp-config.php

Edit the wp-config.php file in the app’s public/ directory and add the following lines:

define('WP_SITEURL', 'http://example.com');
define('WP_HOME', 'http://example.com');

Fix WordPress redirecting to an IP address

To fix WordPress redirecting to an IP address, use the same steps shown above for fixing WordPress redirecting to the wrong domain.

Fix WordPress 404 errors

WordPress will show 404 Page Not Found for all pages if the app’s .htaccess file is missing. When the .htaccess file is missing, permalinks will not work so you will see 404 Page Not Found errors for URLs that rely on permalinks.

To fix this error, update your permalink settings:

  1. Log into the WordPress dashboard.
  2. In the Settings menu, click on Permalinks.
  3. Select your desired permalink structure and click Save changes. WordPress will recreate the .htaccess file with your permalink settings.

Fix WordPress showing blank pages

If WordPress is showing blank pages, the problem is often due to one of the following.

  1. An incompatible plugin.
  2. An incompatible theme.
  3. A missing wp-content/themes/ directory.

Check plugin compatibility

To determine if an incompatible plugin is causing the problem, temporarily deactivate all plugins to see if WordPress is working correctly when there are no plugins enabled.

If you are unable to log into the WordPress dashboard, deactivate all plugins using WP-CLI.

If you are not able to use the WP-CLI, rename the wp-content/plugins/ directory to wp-content/plugins-old/.

Check theme compatibility

To determine if an incompatible theme is causing the problem, temporarily change the WordPress theme to the default WordPress theme to see if WordPress is working correctly when the default theme is used.

If you are unable to log into the WordPress dashboard, change the theme using the WP-CLI.

Fix WordPress showing PHP errors

If any WordPress plugins are not compatible with the PHP version your app is currently using, WordPress may show PHP errors.

To see if using a different PHP version resolves the problem, change the app’s PHP version. Try using each PHP version available on your server to see if WordPress works with any of the available PHP versions.