there has been a critical error on this website – Quick Fix
There has been a critical error on this website is one of the most scary messages you would get while you are working with WordPress. But actually, it is quite easy to fix. In this post, I am going to show you how to easily identify the underlying reason for this message and fix that in a quick, and easy way.
500 Error Message Source
This message comes from an error handling class WP_Fatal_Error_Handler
when something goes wrong during the serving of a webpage in WordPress. Here is the extract of the code from class-wp-fatal-error-handler.php
file:
if ( true === $handled && wp_is_recovery_mode() ) {
$message = __( 'There has been a critical error on this website, putting it in recovery mode. Please check the Themes and Plugins screens for more details. If you just installed or updated a theme or plugin, check the relevant page for that first.' );
} elseif ( is_protected_endpoint() && wp_recovery_mode()->is_initialized() ) {
if ( is_multisite() ) {
$message = __( 'There has been a critical error on this website. Please reach out to your site administrator, and inform them of this error for further assistance.' );
} else {
$message = __( 'There has been a critical error on this website. Please check your site admin email inbox for instructions.' );
}
} else {
$message = __( 'There has been a critical error on this website.' );
}
If you are just looking for a way to customize the error message screen, or just changing the “there has been a critical error on this website” message to something more useful, check out our guide on How To Change WordPress Critical Error Page Content.
Troubleshooting 500 Errors on WordPress
To quickly resolve this issue we need to understand the underlying error first. Server-side 500 errors are generally caused by a faulty PHP code or sometimes a missing PHP file. Ask yourselves the below questions to narrow it down:
- Did you update or delete any files recently on the server? Fixing Corrupt Files
- Did you run any updates on your WordPress admin interface? Reverting Updates
- Did you just enable or disable a plugin?
- Are you able to log in to wp-admin without any issues?
If you gathered initial answers around those questions let’s work our way towards the solution.
Fixing Corrupt Files
If you have recently updated or deleted a PHP or htaccess file on the server, that could be the source of that error message on your site. If you have an older stable version of the updated file, you can either use FTP or a File Manager interface on your server to revert the modified file or files to the stable version.
To restore a file manually using FTP first you need to use an application like Filezilla to connect to your server. You can generally use your hosting account username and password to connect to your server using FTP. But sometimes hosting companies will provide you with an extra FTP username and password for security reasons.
Warning: Uploading an incorrect file to your hosting can break or create security leaks on your site. Please only use this option if you are sure of the correct location.
Once connected locate the original file on your computer and upload the file to the corrected location on the server. This should then revert the file to its original state. You can use FTP to restore your theme and even WordPress to its original state.
If you don’t have an older version then you could try restoring a backup on your server.
Reverting Updates
Sometimes critical errors may be caused by a plugin or WordPress core update. Some WordPress updates may break backward compatibility or require a higher version of PHP which may result in critical errors. In that case, reverting the update manually can resolve the issue. However, if that is a requirement update on WordPress core, we advise you to fix that issue on your hosting. Because requirement updates are generally raised to make your website more secure. See the brief steps required for both options below.
Reverting plugins, themes, or wordpress to its previous state can be a hard task if you don’t have any backup options available. If you have a backup option you can skip this paragraph.
Reverting updates with no backup option requires FTP access to the server. Just like restoring a file as explained in the previous section, you need to restore all the files in the updated plugin or theme directory. To be able to do this, first visit the official plugin or theme download page. On the page, you will need to look for a link to previous revisions where you can get the zip file containing all the files you need to upload. Once downloaded unzip the file, connect to your server, and upload all files to the correct location on your server.
If you have a backup option on your server you can go to backup settings and click restore next to your previous backup. You just need to make sure it is only reverting files. Some servers store a complete backup (both files and database). Reverting to an earlier database backup will undo any posts or page updates you have done after the backup date. However a file-only backup will restore only theme, plugin, or core files and it will keep your data intact (posts pages, etc.)
Fixing PHP Version and Packages on CPanel
If the error is caused by a WordPress core requirement update, we suggest you upgrade your PHP version on the server. If you are using a CPanel hosting server, you can easily do this by searching PHP on the dashboard, and on the PHP version selector, you can easily switch to a newer version. Just make sure to select all required packages on the version selection screen. If you are not using CPanel you may need to request this update from the hosting company.
Fixing Issues Caused by Faulty Plugins or Themes
If you accidentally enable a faulty plugin or theme, this may lock your site completely with a critical error. In that case, you will need a File Manager or FTP access to disable this theme or plugin.
Once connected to your root directory go to wp-themes to disable themes, and wp-plugins to disable plugins. Renaming a plugin or theme source directory automatically disables the plugin or theme. Next time you launch your site you will see that theme or plugin as disabled on the admin interface. You can then select and delete it from the server completely. If you are unsure which plugin causes the issue, renaming wp-plugins will disable all your plugins.
However, this should be your last resort for fixing that kind of issue. Because it will not completely fix the issue, and sometimes a partially working website may be worse than a broken one.
Debugging WordPress: Correct Way
Debugging is like investigating the footsteps of a program just before an error occurs. It provides an error output, which generally helps developers identify the source of the issues more easily because it tells where and why the issue happened. Debugging is disabled by default on WordPress installations because this kind of output can include a lot of extra information about your WordPress installation and it can be a huge security threat for your website. Additionally, this generally generates a lot of messy text and your visitors would be confused seeing that. However, it is generally very helpful to identify the source of the critical errors. That is why, it has a second switch on WordPress that is called debug logging.
You should never have the debug option on without the debug log option. Because having to debug on only displays all debug code in the front end. We only want to see debug text on a log file that is stored on the server. That’s why we need to turn both the debug and debug log on while keeping the debug display off.
You can enable debug logging by putting the following code into your wp-config.php file. That file is very critical and often contains secrets like database name and password. That’s why you should take precautions while updating or sharing the file with someone.
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );
define( 'WP_DEBUG_DISPLAY', false );
Once you have updated wp-config.php on your server, you need to visit the page creating the critical error a few times. This way we make sure it is outputting some log on the debug log file. Debug log file is generally located under the wp-content directory and you can view the contents of the file using FTP or a file manager app on your hosting.
Once debugging is enabled and you have visited the error page a few times, you should see the name of the PHP file causing the issue in the log file. Sometimes you may see a lot of other non-critical issues on the log file. You can then search for “fatal” in the file and that should help you identify the most critical error more easily.
See Also: WordPress.com vs WordPress.org – Comparison with Use Cases
Conclusion
A critical error page can haunt your website anytime a PHP or htaccess issue occurs on your WordPress installation. Those issues are generally caused by invalid syntax and missing or duplicate definitions on the PHP files. It can happen while updating a file on the server, updating a plugin, or theme, or even while upgrading your WordPress installation. In this post, we tried to explain all the ways to fix this issue quickly and easily.
Did you find this information useful? Share your experiences in the comments below.