23

I have installed magento 2 and it working.I just created the Hello world module and it working now.

My issue was I had called non existing method in execute method.

While trying to get it to work I tried to load the page it shows blank white screen, but no error.

How do I get errors to display in magento2?

Ranjit Shinde
  • 1,121
  • 1
  • 7
  • 22
  • What did you tried so far? Show your code! Please edit your question! – jogo Jan 06 '16 at 09:36
  • Enable developer mode using the CLI command `php bin/magento deploy:mode:set developer` as shown [here](http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-mode.html#config-mode). – Steve Johnson Jan 07 '16 at 15:02
  • Check the webserver's error_log, too. In hosting environments, it is normally written to a subfolder in `~/`. – Krista K Jul 09 '19 at 20:33

7 Answers7

41

Add following code in index.php file :-

error_reporting(E_ALL);
ini_set('display_errors', 1);
Pratik Oza
  • 529
  • 3
  • 5
  • 1
    Setting developer mode does not makes fatal errors display. In my case I saw white page. This one fixes :) Thanks. – l00k Jul 12 '17 at 12:58
  • for initial white-page errors (pre-magento / PHP) this does provide better results. – Rock_Artist Aug 31 '17 at 09:50
  • This is already contained in `app/bootstrap.php` as a commented code line. One may also remove the comment there… – feeela Nov 21 '19 at 14:57
  • First, check your `php.ini`. If error_reporting or display is turned off there, you should fix it there instead of in the `bootstrap.php`. Otherwise you end up displaying errors in production and maybe leaking sensible data. – stollr Jul 23 '20 at 09:57
  • There some latest blog available for the same https://www.codedecorator.com/blog/how-to-enable-error-log-in-magento2-4/ – Bhupendra Jadeja Jan 08 '22 at 06:23
38

Enabling Error reporting in magento2 is little tricky , as magento2 now comes with 3 different modes

  1. Default
  2. Developer
  3. Production

Magento2 by default install in “default” mode and thats why you dont get the error log at the front-end of the site , that can a viewed at magento error log . You may check the complete details over here http://devdocs.magento.com/guides/v2.0/config-guide/bootstrap/magento-modes.html

How to enable developer mode in Magento2

This is must have if you are a developer and building extension and template for magento2 , magento provide a command for this purpose . Login in to your linux terminal and under magento execute

php bin/magento deploy:mode:set developer

and it will enable the developer mode under your magento instance for production mode you can set the mode to production or default .

still if you are experiencing in error reporting

you can give a try by renaming local.xml.sample to local.xml under pub/errors

webkul
  • 2,836
  • 10
  • 47
  • 61
14

There is a place for this. In bootstrap.php, there is:

#ini_set('display_errors', 1);

Just uncomment that.

Joe
  • 1,330
  • 13
  • 15
8

1) app/bootstrap.php, there is:

#ini_set('display_errors', 1);

Kindly uncomment that.

2) Run below commands

php bin/magento deploy:mode:set developer
php bin/magento cache:clean
php bin/magento cache:flush
Nilesh Gosai
  • 261
  • 2
  • 6
  • `php bin/magento cache:clean` is a subset of `php bin/magento cache:flush`, in other workds you only need run the `cache:flush` – Barry Apr 17 '19 at 07:55
3

To check current mode use:

bin/magento deploy:mode:show
shustr8
  • 93
  • 7
2

Instead of editing index.php or app/bootstrap.php file, you can also edit the .htaccess file to enable PHP display errors settings.

Write the following lines of code at the end of the .htaccess file present in your Magento2 website's root directory:

## enable PHP's error display settings
php_value display_errors on
## set error display to E_ALL
php_value error_reporting -1

After that,

  • Open terminal
  • Go to your Magento's root directory

    cd /path/to/your/magento/root/folder
    
  • Run the following command to enable developer mode:

    php bin/magento deploy:mode:set developer
    
  • To check your current developer mode, you can run the command:

    php bin/magento deploy:mode:show
    
Krista K
  • 21,503
  • 3
  • 31
  • 43
Mukesh Chapagain
  • 25,063
  • 15
  • 119
  • 120
1

Please Put the following code in index.php

   ini_set('error_reporting', E_ERROR);
   register_shutdown_function("fatal_handler");
   function fatal_handler() {
     $error = error_get_last();
     echo("<pre>");
     print_r($error);
   }