WordPress errors and solutions

WordPress has some weird and wonderful errors. I’m documenting them here as I find them, ideally with their solutions.

The error: The optional module, <module>, is not installed, or has been disabled.

This example deals with the intl package because that’s the most recent error WordPress came up with for me, but there are many other packages that you may be missing.

The Health Status screen shows this error (or a similar one showing other packages):

Site Health Status: The site health check shows critical information about your WordPress configuration and items that require your attention.

The cause

The specified package hasn’t been installed on your server or, if it has, it hasn’t been enabled.

There is a list of PHP extensions that WordPress makes use of; if any of these, including optional extensions, are missing from your server, you will get this warning from Site Health.

The solution

There are two steps to solving this problem:

  1. If phpx.y-intl, where x.y is the version of PHP used by your WordPress installation, is not installed on your server, you need to install it.
  2. If phpx.y-intl is not enabled on your server, you need to enable it.

Both are easy to do.

Installing phpx.y-intl

Check your phpinfo to see what version of PHP your server is using. Mine is (currently) using PHP 7.4, although php --version shows that PHP 8.1 is also installed, which is why it’s best to look in phpinfo.php. This file also tells you where your php.ini file, which you’ll need in the next step, is.

First, enter the following in your command-line interface:

sudo apt install php7.4-intl

Check again with the WordPress Health Screen to see if the error has been fixed or not. If it has not, you will need to enable the module.

Enabling phpx.y-intl

Find out from phpinfo.php where your server hides its php.ini file. Open php.ini using your favourite editor (e.g. nano, vi, Emacs) and search for intl. When you find it, it will be commented out with a semi-colon. Delete the semi-colon and save the file:

[…]
;extension=gmp
;extension=intl
;extension=imap
[…]

[…]
;extension=gmp
extension=intl
;extension=imap
[…]

To get WordPress to notice the change, you need to reload Apache:

sudo service apache2 reload

The module should now be listed in phpinfo.php. Check with WordPress to make sure the error has gone away – it might take a little while for it to filter through, so give it a while before you convince yourself everything is irretrievably broken.

More information

More details about this error are givin in Adding/enabling missing PHP modules in WordPress.

The error: Error establishing a database connection

You try to load, reload, save, preview, etc. a page in your browser; it takes forever before keeling over displaying this error:

Error establishing a database connection
Error establishing a database connection

There may or may not be other information given.

The cause

Error establishing a database connection suggesting that your credentials are incorrect or your database server is not running

If there is extra information given, it might tell you that your credentials (i.e. your username and password) are wrong, but if you haven’t changed them or your wp-config.php file for a while, that’s probably not the cause. It’s more likely that they can’t contact your database server because it has stopped running for some reason.

The solution

You need to restart the database by typing this into a command line attached to your server:

sudo service mysql start

If the problem recurs

If you get this error a lot, and it’s not because you’re hammering it yourself with edits and updates and whatnot, then there might be something more sinister afoot. Have a look at my investigations into this database error for some clues as to what might be happening with your database server.

The error: Error reconnecting to the database

This is a component of the The error: Error establishing a database connection.

The cause

Error establishing a database connection suggesting that your database server is not running

Either your database server has stopped running or it’s under too heavy a load to cope with your request.

The solution

See The error: Error establishing a database connection for how to rectify this error.

The error: Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

This error appears instead of the page you were expecting:

Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

Don’t panic!

The cause

If your site was working fine a moment ago, and you haven’t changed anything on your server, then your server has probably stopped.

The solution

The solution is easy if you haven’t changed anything on your server; just type this into a command line attached to your server:

sudo service apache2 reload

That should fix it. Now breathe.

Background information

I’ve written more about how I found this fix, which turned out to be much simpler than I’d envisaged.