Fixing magento issues

[Solved] An error has happened during application run. See exception log for details Magento 2

Pinterest LinkedIn Tumblr

Sometimes when working with Magento 2, you will see the error message:

An error has happened during application run. See exception log for details. Could not write error message to log. Please use developer mode to see the message

An error has happened during application run magento 2

This is a common error that Magento 2 users may encounter when upgrading Magento 2 version or even after installing a new Magento 2 instance.

Some users reported to me that after failed to upgrade Magento 2 version, they use rollback button to revert version and see this error message.

In this tutorial, we will learn everything about this error, the cause and solution.

Cause of the error

The error message only tells you that there’s a problem happening with Magento 2.

There are several causes of this error like

Each type of error has different solution, in the next part we will learn about all possible cause of this error and how to fix them

Solution

Quick fix you should try first

First, run these command using ssh, it may immediately fix your issue. In most case, the issue happens because Magento 2 code was not compiled.

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:Deploy -f
chmod -R 777 var/ generated/

If the issue still persists, find more solutions below.

Different websites have different causes of error. To find out exactly the cause of the error on your site we will need to enable developer mode to display detailed error messages

After enabling developer mode, if you see the following error message:

Exception ‘PDOException’ with message ‘SQLSTATE[HY000] [1049] Unknown database

Sample error message

exception 'PDOException' with message 'SQLSTATE[HY000] [1049] Unknown database 'magentip'' in G:\Xxamp\htdocs\magento2.1.2\vendor\magento\zendframework1\library\Zend\Db\Adapter\Pdo\Abstract.php:129 Stack trace: #0 G:\Xxamp\htdocs\magento2.1.2\vendor\magento\zendframework1\library\Zend\Db\Adapter\Pdo\Abstract.php(129): PDO->__construct('mysql:host=loca...', 'root', '', Array) #1

This means there’s a problem with your MYSQL service.

You can try restart MySQL using this command

service mysql restart

Or double check if MySQL database information is correct in /app/etc/env.php

Check the following information

‘host’ => ‘localhost’,
‘dbname’ => ‘magento2dbname’,
‘username’ => ‘db-username’,
‘password’ => ‘dbpassword’,

dbname = database name, username = database username, password = database password.

main.CRITICAL: Exception: Deprecated Functionality: Function mcrypt_module_open() is deprecated

Sample error message

main.CRITICAL: Exception: Deprecated Functionality: Function mcrypt_module_open() is deprecated in /home/magentip/public_html/hpe/vendor/magento/framework/Encryption/Crypt.php on line 54 in /home/magentip/public_html/hpe/vendor/magento/framework/App/ErrorHandler.php:61
Stack trace:
#0 /home/magentip/public_html/hpe/vendor/magento/framework/Encryption/Crypt.php(54): Magento\Framework\App\ErrorHandler->handler(8192, 'Function mcrypt...', '/home/magentip/...', 54, Array)
#1 /home/magentip/public_html/hpe/vendor/magento/framework/Encryption/Encryptor.php(401): Magento\Framework\Encryption\Crypt->__construct('5c773093231aabe...', 'blowfish', 'ecb', false)

If you see such error message > There was problem with folder permission

Run these command to fix this issue

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find ./var -type d -exec chmod 777 {} \;
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;
chmod 777 ./app/etc
chmod 644 ./app/etc/*.xml

and

chown -R www-data:www-data /var/www/yourmagento2folder/

main.DEBUG: URI ‘/” cannot be accessed with HEAD method (Magento\Cms\Controller\Index\Index)

Sample error message

main.DEBUG: URI '/'' cannot be accessed with HEAD method (Magento\Cms\Controller\Index\Index) [] []
main.DEBUG: Request validation failed for action "Magento\Cms\Controller\Index\Index\Interceptor" [] []
main.DEBUG: URI '/checkout'' cannot be accessed with OPTIONS method (Magento\Checkout\Controller\Index\Index) [] []
main.DEBUG: Request validation failed for action "Magento\Checkout\Controller\Index\Index\Interceptor" [] []

Run database update, clear cache, compile code to fix this

chmod -R 777 var/ generated/
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento c:f

PHP Deprecated: The each() function is deprecated. This message will be suppressed on further calls in

Sample error message

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /var/www/html/vedic/vendor/colinmollenhour/cache-backend-file/File.php on line 81

If you see this error message, try to downgrade or upgrade your PHP version (another version may probably fix your error

main.CRITICAL: Class Magento\Framework\App\Http\Interceptor does not exist

Sample error message

main.CRITICAL: Class Magento\Framework\App\Http\Interceptor does not exist {"exception":"[object] (ReflectionException(code: -1): Class Magento\\Framework\\App\\Http\\Interceptor does not exist at /var/www/magento/vendor/magento/framework/Code/Reader/ClassReader.php:26)"} []

This error may happen when you install Magento 2.4 with Nginx as a reserve proxy

You can fix this by increase the proxy buffer in the Nginx conf file

server {
    ...
    location / {
        proxy_pass  http://192.168.1.99;

        ...

        proxy_buffers              256 8k;
        proxy_buffer_size          512k;
        proxy_busy_buffers_size    512k;
    }
    ...
}

Wrapping up

I have listed all the possible solutions to fix the issue “An error has happened during application run. See exception log for details Magento 2”

In case you tried all the mentioned solutions but the error still persists, just drop a comment below with your error message (after putting Magento 2 developer mode). I will be happy to help.

Good luck solving this error.

Hung Tran is the main editor of magentip.com, he loves to write about everything related to Magento 2

2 Comments

  1. i have many issue and it never been fix i try many way can you please advice

Write A Comment