Enabling "development mode" on a local Drupal 8 site

Drupal 8 includes some great debugging tools built-in, but it isn't always super-obvious how to access them. Luckily, the Drupal Console "site:mode" command helps out quite a bit, but it also requires the site to be configured properly before it can be successfully used. I find that having access to the Twig template name suggestions is invaluable when theming a Drupal 8 site:

Twig template name suggestions

Enabling development mode on a Drupal 8 site gives site builders access to debugging functionality including:

  • Enables Twig debugging - template override filename suggestions right in the HTML source.  
  • Enables Twig auto-reload - Twig templates are automatically recompiled when they are changed (instead of having to wait for a cache rebuild).  
  • Disables Twig caching and Drupal's render cache - because caching is annoying when you're developing, right?  

Using Drupal 8's development "mode" simply involves tweaking your local site's settings.php and services.yml files. Drupal Console's "site:mode" command will do most of the work for you.

Here's the steps I normally take to enable Drupal 8's development mode:

  1. Ensure the local copy is using a sites/default/settings.local.php, and that it is being included by the sites/default/settings.php file.  
  2. Copy /sites/development.services.yml to sites/default/services.yml. The services.yml file is ignored by Git by default, and contains environment-specific services settings.  
  3. Ensure the permissions of the sites/default/services.yml file allow you to read/write, as when you run Drupal Console's "site:mode" command, the file will be modified. This is a common issue when first setting this stuff up.  
  4. Run Drupal Console's "site:mode" command to put the site in development mode: drupal site:mode dev.  

If all goes well, then Drupal Console will output a summary of the changes it made, with no errors.

Drupal Console development mode output

You can then flip-flop between development mode and production mode using:

drupal site:mode dev
drupal site:mode prod

Keep in mind that Drupal will try to protect the /sites/default/services.yml file, so you may have to update its permissions prior to each time you change the site mode.