As I write this article, PHP 7.4 has reached the end of its life cycle, so it will no longer receive security updates. It’s time to update PHP, so I’ll summarize how we can try to prevent errors on the website. I will also describe the issues I faced on different hosts where I have joomla and wordpress websites and what was the solution. Sometimes the hosting provider updates the PHP and website owners only face an error message on their website. In case of a 500 Error, try contacting the hosting provider to see if they can solve the problem. This article is more about avoiding errors, but at the end of the article there are 1-2 tips for 500 Errors as well.
1. Compatibility check
First of all, check which PHP version your software is compatible with. It’s not that simple. It will only be revealed afterwards that some of our extensions are not compatible, so we may not be able to avoid the error messages mentioned in the post title. Don’t upgrade to the latest PHP version! When I write this article, you should upgrade from PHP 7.4 to 8.0. Information about wordpress compatibility can be found here.
2. Backup and update
Backup your website and update WordPress, the theme and the plugins. Test your website after the updates!
3. Display or log errors
We need to make the following changes in the wp-config.php file:
// switch on WP_DEBUG
define( 'WP_DEBUG', true );
// error log into the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// do not display errors
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
It then writes error messages into the /wp-content/debug.log file.
4. PHP version change
You can change the PHP version in the cpanel. If only the MultiPHP manager is available in the cpanel, then the new PHP version must be set there, and then a few PHP directive values should be set in the MultiPHP ini editor. For wordpress, I recommend the following minimum values: memory_limit=512M, post_max_size=32M, upload_max_size=32M. With the increased memory_limit, we can avoid the following error:
Fatal error: Allowed memory size of 33445566 bytes exhausted
If only the Select PHP version is available in the cpanel, then the new PHP version and the PHP directive values must also be set there. You can even activate PHP extensions/modules here if necessary. To ensure the database connection, it is worth turning on the PHP modules shown in the image below, but if there is no mysqlnd, then look for mysqli. WordPress also requires the activation of the imagick module.
This way we can avoid the following types of error messages:
PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in public_html/wp-includes/class-wpdb.php:1810
In the case of other error messages, you may need to disable the wordpress plugin that the error message refers to, because it may not be compatible with the new PHP version. To do this, we need to go back to the previous version of PHP in the cpanel in order to be able to login to the WordPress admin interface. Renaming the plugin’s directory may also work, so that you can log in WordPress.
Finally, once we have eliminated all errors during thorough testing, set back define(‘WP_DEBUG’, false) in the wp-config.php file and delete the debug.log file!