Enabling "development mode" on a local Drupal 8 site

Published March 25, 2016

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.

Resources

Comments

Hi!
I see you are changing settings for enabled modules could this also be used to enable say, the shield module on the test and live site before the website goes public?
Thanks for the blog post!
Frederick

Submitted by Frederick (not verified) on Wed, 02/08/2017 - 05:38

Drupal Console version 1.0.0-rc15
drupal site:mode dev
[ERROR] Command "site:mode", is not a valid command name.

I am finding documentation about the site:mode command but it does not appear to be in the latest version of Drupal Console.

Submitted by Frederick (not verified) on Thu, 02/09/2017 - 10:01

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!

Name
CAPTCHA