Drupal ^8 || ^9 - Set up Development Environment

Set up Drupal Development Environment

The Topic: As we are developing a Drupal site, we need to be able to de-bug. This article steps through setting up a Drupal Development environment.

The Process

Below are the steps to take.

  1. Copy / create settings.local.php file;
  2. Uncomment in the settings.php file;
  3. Uncomment ind setting.local.php;
  4. Disable CSS and Javascript aggregation;
  5. Disable caching;
  6. Prevent Drupal from picking up tests; and
  7. Set Twig debugging to true.

1. Create settings.local.php file

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

2. Modify settings.php file

In settings.php, uncomment the following:

if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
  include $app_root . '/' . $site_path . '/settings.local.php';
}

3. Modify settings.local.php file

Ensure that the following is uncommented in settings.local.php:

$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';

4. Disable CSS and Javascript aggregation

In settings.local.php ensure that the following is uncommented:

$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;

5. Disable caching rendered HTML and Dynamic Pages module

In settings.local.php ensure that the following is uncommented:

$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

6. Prevent Drupal from picking up tests in modules

In settings.local.php ensure that the following is changed from TRUE to FALSE:

$settings['extension_discovery_scan_tests'] = TRUE;

7. Set Twig debugging to true

In /sites/development.services. yml add the following:

twig.config:
    debug: true
    auto_reload: true
    cache: false

The final file will look like:


# Local development services.
#
# To activate this feature, follow the instructions at the top of the
# 'example.settings.local.php' file, which sits next to this 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

Final checks

In /default/settings.local.php ensure that $settings['rebuild_access'] is set to FALSE.

Ensure that Aggregate CSS files and Aggregate Javascript files is un-checked at /admin/config/development /performance

Hire Me? Lets talk!

I am available for remote freelance work to select clients. Please contact me

Related Articles

If you enjoyed this, you may also want to read..

References

This article was based on the following excellent reference:

Comments

Permalink

Patrick, question on your development environment article. The three cache settings in the local.settings.php are active in a development situation. However, you need to comment out those lines when you bring a cloned project to a local container for the first build. Then once the project is up, you can go back into the local.settings.php file and remove the # like you want in a development environment and do a rebuild. The only way I have figure to make the build, then operate work is to have two copies of the different versions of my local.settings.php file tucked away in a subdirectory and write a script to run the first at build, the second for the rebuild rather that edit the active file for a rebuild to make it easier. You happen to have any genius ways you have approached this? Emmonspatzer@yahoo.com

Hello Emmons, thanks for the comment.

This may sound odd, however I do not have much experience with containers! I also do not use a local dev environment. I do all my work on virtual servers - dev and production. Because I am not exclusively dev, and cover many other solopreneur related tasks, I found that this work flow is way more efficient for me.

That said, it seems to me that your solution is a good one, one that I would probably have adopted. All the best.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.