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:
Enabling development mode on a Drupal 8 site gives site building 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:
- 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.
- 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.
- 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.
- 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.
You can then flip-flop between development mode and production mode using:
drupal site:mode dev<br>drupal site:mode prod
Resources