Fix “There Has Been a Critical Error on This Website” via CLI (WP-CLI)

Fix “There Has Been a Critical Error on This Website” via CLI (WP-CLI)

You’re working on your WordPress website when suddenly the screen goes white, and a message pops up: “There has been a critical error on this website.” If you’re like most WordPress users, this message strikes a sense of dread into your heart. But don’t worry! There is a highly efficient, lesser-known method to diagnose and fix this issue: using the WordPress Command Line Interface, or WP-CLI.

Instead of struggling with cPanel file managers or attempting trial-and-error plugin removal, WP-CLI allows you to take direct, quick control of your WordPress site—all without needing to open a single browser tab. In this article, we’ll walk through how to diagnose and fix the infamous “critical error” using WP-CLI with confidence.

What Causes the “Critical Error” in WordPress?

All Heading

Before we dive into the fix, let’s first understand what causes this frustrating problem. WordPress will show a critical error for a range of reasons, such as:

  • Plugin conflicts
  • Theme issues
  • PHP errors or version mismatches
  • Corrupted core files
  • Database connection issues

This message is essentially WordPress telling you that something went wrong at the code level and needs immediate attention. While the web interface gives you limited visibility, the command line reveals everything you need to know under the hood.

Why Use WP-CLI to Fix This Issue?

WP-CLI is a powerful command-line tool for managing WordPress installations. Here’s why it’s particularly helpful for resolving critical errors:

  • Works even when WordPress admin is down
  • Allows rapid plugin/theme management
  • Enables direct database interactions
  • No need for FTP or control panel navigation

If you’re a site owner, developer, or server admin, gaining proficiency with WP-CLI can drastically reduce your downtime and frustration.

Step-by-Step Guide to Fixing the Critical Error Using WP-CLI

1. Connect via SSH

The first step is logging into your server through SSH. You’ll need credentials from your hosting provider. A typical SSH login command looks like this:

ssh your-username@your-server-ip

Once connected, navigate to your WordPress directory:

cd /path/to/your/wordpress-site

2. Deactivate All Plugins

Most WordPress critical errors are caused by plugins. A quick way to determine if plugins are the culprit is by deactivating them all:

wp plugin deactivate --all

Now try accessing your site again. If it loads correctly, it confirms that a plugin is causing the problem. You can gradually reactivate plugins one by one until you identify the troublemaker:

wp plugin activate plugin-slug

Tip: Replace plugin-slug with the actual directory name of the plugin.

3. Switch to a Default Theme

If plugin deactivation doesn’t fix the issue, it may stem from your active theme. Switch to a default WordPress theme like Twenty Twenty Three with this command:

wp theme activate twentytwentythree

This will override your current theme. If the site starts working again, you’ve found the culprit!

4. Check for PHP Errors in Debug Mode

To gather more information, enable WP debugging via CLI. Start by modifying the wp-config.php file:

wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_LOG true --raw
wp config set WP_DEBUG_DISPLAY false --raw

This causes WordPress to log all errors into wp-content/debug.log without displaying them on the screen (more secure). Then view the error log:

cat wp-content/debug.log

Look for fatal errors or uncaught exceptions—these usually point to the exact file and function causing the problem.

5. Check the Site’s Health

WP-CLI can also provide insights into the overall health of your installation:

wp site health info

Also, try:

wp core verify-checksums

This command checks whether any core WordPress files are corrupted or have been tampered with. If mismatches are reported, you may need to reinstall core files:

wp core download --force

6. Review PHP Modules and Version

Sometimes, themes or plugins demand certain PHP modules that aren’t installed or are incompatible. Check your PHP version like so:

php -v

Then, verify needed PHP modules with:

php -m

Cross-reference with your theme or plugin documentation to confirm needed modules like curl, mbstring, or json are present.

7. Check Database Connection

In some cases, database problems can trigger critical errors. Run this command to verify the connection:

wp db check

If issues are detected, repair with:

wp db repair

For deeper issues, you can also run:

wp db optimize

8. Reinstall WordPress Core (If All Else Fails)

If none of the above steps resolve the error, reinstall WordPress core files using:

wp core download --force

This won’t affect your themes, plugins, or uploads; it simply replaces core files in case they’ve been compromised.

Best Practices to Prevent Future Critical Errors

Once you’re back online, take these steps to avoid future disruptions:

  • Backup regularly: Use WP-CLI to automate backups for speedy restores.
  • Use a staging site: Test plugin/theme updates in a separate environment.
  • Monitor site health: Use wp doctor (an extension of WP-CLI) for scheduled health checks.
  • Lock down file permissions: Prevent unauthorized modifications to crucial files.

Final Thoughts

Seeing “There has been a critical error on this website” doesn’t mean the end of your WordPress site. With the help of WP-CLI, you can troubleshoot and fix these issues swiftly and professionally—even when your site isn’t accessible through the admin dashboard.

Whether you’re managing a personal blog or a complex e-commerce store, mastering WP-CLI gives you a backstage pass to managing your WordPress installation beyond the usual tools. It may seem intimidating at first, but once you see how much faster and cleaner it is, you’ll never go back.

So the next time your screen goes white, don’t panic. Pull up your terminal, connect via SSH, and let WP-CLI save the day.

Happy coding and even happier troubleshooting!