51

I'm installing Drupal 8 core (using the standard profile). Whenever I get an exception/error, I get a blank page with "The website has encountered an error. Please try again later." (As shown in the image below.) This is shown as text and has no details or tracing about the error.

Error: The website has encountered an error. Please try again later.

How do I enable developer/debugging mode?

1

9 Answers 9

64

On a development site I would suggest uncommenting the following lines in the settings.php file. emacs sites/default/settings.php

if (file_exists(__DIR__ . '/settings.local.php')) {
  include __DIR__ . '/settings.local.php';
}

and then copying the file example.settings.local.php from /sites folder to /sites/default folder and rename it to settings.local.php

cp sites/example.settings.local.php sites/default/settings.local.php

In addition to adding the following setting

$config['system.logging']['error_level'] = 'verbose';

it also adds a few other settings which will help you in debugging and making development easier. If you don't want any of them in particular, you can always comment them out.

Note : If you think adding a file_exists call to each page will slow down the site, you can always remove it in the production code.

3
  • If you don't have an example file, you can also just create a file containing <?php $config[...; Commented Feb 20, 2016 at 0:24
  • 1
    As mentioned below the Devel module can make things easier for Drupal 8. Verified that the $config['system.logging']['error_level'] = 'verbose'; settings appears to work. Commented May 2, 2017 at 16:41
  • I have created a docker container that comes with the necessary settings for debugging and non-caching - hope it's useful: hub.docker.com/r/feikede/drupal-dev Commented Sep 17, 2018 at 11:00
20

Add the following line in the settings.php file.

$config['system.logging']['error_level'] = 'verbose';

See Make developer tricks / tools for D8 more discoverable/obvious for more details.

17

An easy option, if you have access to Drupal Console, is to enable the development/debugging environment using drupal site:mode dev; when you are ready to change it back to production, use drupal site:mode prod.

3
  • 1
    Nice trick with the Drupal Console Commented Mar 2, 2017 at 20:43
  • Didn't know you could do this! w00t! Commented Jan 8, 2020 at 10:06
  • 6
    Is there something similar for drush?
    – Benedikt
    Commented Feb 9, 2020 at 9:26
13

Here is the variable with the different values :

$config['system.logging']['error_level'] = 'all'; // hide|some|all|verbose

These error levels are defined in the Drupal Core Bootstrap, here is the details for each one :

/**
 * Error reporting level: display no errors.
 */
const ERROR_REPORTING_HIDE = 'hide';

/**
 * Error reporting level: display errors and warnings.
 */
const ERROR_REPORTING_DISPLAY_SOME = 'some';

/**
 * Error reporting level: display all messages.
 */
const ERROR_REPORTING_DISPLAY_ALL = 'all';

/**
 * Error reporting level: display all messages, plus backtrace information.
 */
const ERROR_REPORTING_DISPLAY_VERBOSE = 'verbose';
4
  • 4
    Yes, thanks for adding the possible values, which were surprisingly difficult to find.
    – arnoldbird
    Commented May 7, 2019 at 14:09
  • @arnoldbird The fact that you were surprised tells me that you hadn't been a Drupal developer for very long when you wrote that comment LOL :P But yes, incredibly difficult to find and thank you @FloDevelop!
    – Kenny83
    Commented Apr 15, 2020 at 6:28
  • @flo-develop any chance anyone can define the "some" option? Or a link to documentation?
    – zkent
    Commented Jul 29, 2021 at 15:14
  • 1
    Hello @zkent, i update my answer with details for each error level. Commented Aug 2, 2021 at 7:31
4

To get basic error messages in Drupal 8 you don't need to touch any code at all. Just go to:

/admin/config/development/logging

and set "Error Messages to Display" to an appropriate level.

You can also view your recent errors through the admin interface:

/admin/reports/dblog

That said, other answers about settings files are relevant – you should only ever make errors visible on your development site, not production.

Overwritten $config objects/keys in settings.php won't be written to the sync directory when exporting, so providing your settings.php is in .gitignore, you can continue to safely use the configuration system to sync between clones of the same site.

2

If you only have access to Drush (no Drupal console) and you are working on a remote server, you can set the config to show all errors:

drush MYSITE.MYENV config-set system.logging error_level all -y

This is useful if you are getting a WSOD on a remote server and can't troubleshoot without more info.

1
  • For the situation described I also highly recommend drush sqlc followed by SELECT * FROM watchdog ORDER BY wid DESC LIMIT 1 to show the last entry in the dblog.
    – Gogowitsch
    Commented Aug 9, 2018 at 19:49
1

Adding $config['system.logging']['error_level'] = 'verbose'; to the sites/default/settings.php should log the error.

I will rather suggest the following steps.

  • Enable Twig debug and disable the cache for development purpose

  • Copy the sites/example.settings.local.php file to sites/default/settings.local.php

  • Un-comment the $settings['cache']['bins']['render'] = 'cache.backend.null'; line in the settings.local.php file

  • On the site/default/settings.php file, un-comment the following lines

    if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
      include $app_root . '/' . $site_path . '/settings.local.php';
    }
    
  • Add the following lines to the sites/development.services.yml file

    parameters:
      http.response.debug_cacheability_headers: true
      twig.config:
        debug: true
        auto-reload: true
        cache: false
    services:
      cache.backend.null:
        class: Drupal\Core\Cache\NullBackendFactory
    

when all steps completed change directory to root dir and rebuild cache ```

  • Run drush cr

You should now see the debug output. Don't forget to undo the changes before deploying to production.

0

You can also install the the Devel and Devel kint modules. This will let you debug using kint(xyz).

0

Blank page with "The website has encountered an error. Please try again later." won't take you anywhere. To get more information out of your Drupal 8 site you can enable following configs.

$config['system.logging']['error_level'] = 'verbose';

For local Drupal 8 development, you should also enable error reporting, display errors and display startup error to help you further debugging and fixing major runtime error.

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

You can find more information about TWIG debugging and enabling debugging with Drupal Console in the blog post below.

https://www.drupixels.com/blog/enable-debug-mode-and-error-reporting-local-development-drupal-8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.