Fixing magento issues

[Solved] Magento 2 Exception Printing is Disabled by Default for Security Reasons

Pinterest LinkedIn Tumblr

When working with Magento 2, sometime you will see the error: There has been an error processing your request – Exception printing is disabled by default for security reasons.

The error looks like this:

there has been an error processing your request magento 2

In this tutorial, we will find out how to force Magento 2 to display full error message and solution to fix each common error message

You may also look for: How to fix Magento 2 Error 503 Backend fetch failed with varnish cache

Cause of the error

In Magento 2, this error normally occurs when you install or upgrade extensions/themes on your site. The installation/upgrade probably caused conflicts on your site => Magento 2 throws that error message.

The error message There has been an error processing your request – Exception printing is disabled by default for security reasons is not a specific error of Magento 2, it only tells you that Exception Printing is currently disabled on your system.

Magento 2 does not show full error message because it will make your system vulnerable to hacker

How to display full error message

To display full error message for debug, follow these steps

Step 1: Find local.xml.sample file located in pub\error in Magento 2 website folder

You can access file on your server using File manager if you have Cpanel/Directadmin

If you’re using a VPS or dedicated server, you can use Winscp/Filezilla to manage file.

Step 2: Rename this file local.xml.sample => local.xml

rename to local.xmlIt should be like this after you rename the file

local xml

Step 3: Reload your website to see full error message

If you’ve done step 2 correctly, now Magento 2 will show full error message instead of There has been an error processing your request – Exception printing is disabled by default for security reasons

Step 4: Enable Developer mode for enhanced debugging and to show errors right on frontend by using this command in ssh:

php bin/magento deploy:mode:set developer

Type of error message and solution

After turning on the debug, you will see various type of messages. Here I will list the most common errors and how to fix them

Unable to retrieve deployment version of static files from the file system.

Unable to retrieve deployment version of static files from the file system

This error happens because Magento 2 didn’t finish deploy static view files.

You can manually deploy static view files using this command:

php bin/magento setup:static-content:deploy

Flush cache and refresh your website, now the error should be fixed

php bin/magento cache:flush

Expecting a string, got NULL

expecting a string got null

This error may happen when you migrate data from Magento 1 to Magento 2, to fix this error run the following command in your ssh

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

SQLSTATE[HY000] [1045] Access denied for user

If you see the following error message => That means you are using wrong database information for your Magento 2 website

Exception #0 (Zend_Db_Adapter_Exception): SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
Exception #1 (PDOException): SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

To fix this error go to /app/etc/env.php and correct your database information

‘host’ => ‘localhost’,
‘dbname’ => ‘databasename’,
‘username’ => ‘database_username’,
‘password’ => ‘password_of_database’,
‘model’ => ‘mysql4’,
‘engine’ => ‘innodb’,

Replace: Databasename, database_username, password_of_database with your correct ones

Finally, flush cache and restart mysql to access your site

Wrong php version

If you see the following error message:

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /opt/lampp/apps/magento/htdocs/vendor/zendframework/zend-stdlib/src/ArrayObject.php on line 426

=> That means you are running a wrong PHP version for Magento 2

To fix this issue, first, check your phpversion using

php -v

Sample output

check php version

If you are running Magento 2.3, try to install php7.2

If you are running Magento 2.4, try to install php7.4 or at least php7.3

Search query throwing error 

Whenever you search a query on your newly installed Magento 2 site, the result page throw the error like this

Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento2.catalogsearch_fulltext_scope1' doesn't exist, query was: INSERT INTO `search_tmp_5eb592164ff260_69624311` SELECT `main_select`.`entity_id`, SUM(score) AS `relevance` FROM (SELECT DISTINCT  `eav_index`.`entity_id`, (((0)) * 1 + LEAST((MATCH (data_index) AGAINST ('test*' IN BOOLEAN MODE)), 1000000) * POW(2, search_weight)) AS `score` FROM `catalog_product_index_eav` AS `eav_index`
 INNER JOIN `catalogsearch_fulltext_scope1` AS `search_index` ON eav_index.entity_id = search_index.entity_id

This error sometimes happens because you have not reindex Magento 2 after making changes

Run the following command to reindex data

php bin/magento indexer:reindex

Warning: SessionHandler::read()

If you see this error

{"0":"Warning: SessionHandler::read(): open(var/www/html/var/session/sess_nloiac096cn9o6imqdkouoj96l, O_RDWR) failed: No such file or directory (2) in /var/www\$

You will see this error when session.save_handler PHP parameter is set to some another session storage than files (for example, redismemcached, and so on). This is a known issue we're working to resolve.

This error occurs when session.save_handler PHP parameter not set to files  session storage (for example session.save_handler is set to save to redismemcached..)

To fix this issue we will setsession.save_handler to files storage

First, locate php.ini file on your server using the following command in ssh

php -i | grep "Loaded Configuration File"

Sample output

php ini location

Here you can see that php.ini file is located in /etc/php/7.0/cli/php.ini, go to that path and edit php.ini, find the following lines:

session.save_handler = files
;session.save_path = "/tmp"

And change it to =>

session.save_handler = files
session.save_path = "var/www/your_magento2_folder/var/session"

Next, edit ./app/etc/env.php, find the following line

'session' =>
     array (
    'save' => 'files',
   ),

And change it to =>

'session' =>
     array (
    'save' => 'files',
    'save_path' => '/var/www/magento2/var/session',
   ),

 

Finally, save file and refresh your website.

Conclusion

The errors I had mentioned in this tutorial are only some common errors. If you do not find the error you want to solve, please drop the error message, log (with screenshot if possible).

I will try my best to help you fix that error and also update the error/solution to this article.

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

1 Comment

  1. Hello Hung

    I’m a totally newbie in magento. I have skills in linux, wordpress, macos but this is the first time I have a client with magento shop and I faced the same issue, once I tried to log in into the admin area. Once I entered user/pass I got the message “There has been an error processing your request. Exception printing is disabled by default for security reasons. Error log record number: 987882184e9b868db9638bdc913510ba0170905862fd2c0de2a3fd22116db31c”
    After a little research I came to your website for the solution. I need your help because:
    The owner of the website has no clue at all from technology. The previous dev got disappeared – and that’s why I offered to help him.
    I have full access to cpanel, hosting provider, everything. But I don’t have a local copy of it – as I see in your example- so to test it here first.
    Can you please guide me, to fix this issue, safely and only through cpanel, file manager and etc? SSH is not an option for now but if I must enable it, I can do it.
    Please I remind only through web/browser any solution you might have.
    For now I have done the steps to enable the printing and I got the following error:
    “Notice: Undefined offset: 2 in /home/terrabeata/public_html/vendor/magento/framework/Encryption/Encryptor.php on line 591”
    My brain will blow. I have no clue what to do with it. Please help.
    Thank you so so much <3

Write A Comment