Fix "An error has happened during application run. See exception log for details" in Magento 2

As you know Magento 2 provides various default options for creating an eCommerce store and gives you enough flexibility to customize it. However, some errors may appear on the way. And as a developer should know how to fix them.

One of the most common errors you might face is "An error has happened during application run. See exception log for details". There are various reasons for it to appear. So the solutions may vary as well. 

If you are wondering how to deal with this error, you've landed on the right page. Today you'll learn more about the error and find a solution you can refer to.

What Causes the Error?

As we've already mentioned, "An error has happened during application run. See exception log for details" is one of the most common Magento errors.

It usually happens after you install Magento 2. Yet, you can also encounter it after upgrading your Magento to a higher version. 

The error in question can be caused by multiple reasons. For example, the database connection is not accurate or the MySQL service is not responding to your server.

At the same time, you might have used the wrong command while installing Magento and some PHP extensions are missing. Any of these things can initiate this error. Nevertheless, you need to know how to fix it.

How to Fix "An error has happened during application run. See exception log for details"?

The error message doesn't tell you much about what exactly has to be fixed. Since it can be pretty much anything, you need to check the logs first.

Review the Magento error logssystem.log, debug.log, and exception.log located in the var/log folder and find the full error message. After that, you'll get some ideas about where to start.

But note that to debug the error you need to enable the development mode. Once you switch to developer mode, you'll discover the full error message and understand what further steps to take. You can set the development mode by running the following CLI command:

php bin/magento deploy:mode:set developer

The following error can also happen due to some inconsistencies in the Magento compilation. Thus you can try this quick solution and see if it helps:

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f

Yet, there may be some other error messages you'll get in the logs. Each of them requires a different approach, since there could be numerous reasons for his error.

Note: you are expected to use a lot of commands when fixing Magento-related issues. But it is of course quite hard to remember all of them. So it is better to have a list of useful Magento 2 commands at hand.  

Just like we've said before, there is no universal solution you can refer to in every single case possible. The most important thing to do is check the logs and switch to the development mode.

It allows you to see the source of the error, establish further steps and work your way through all relevant fixes.

At the same time, "An error has happened during application run. See exception log for details" is not the only error that you might have to deal with.

So being aware of more Magento 2 troubleshooting techniques will come in handy not only for solving the issues but preventing them.