Skip to main content

Drupal 8: Setting up a local developent website standard workflow

Every time i have to start and install a local drupal development website i find my self doing the same things (what a suprise!). So this is how i proceed after the installation.

Step 1

Open web/sites/default/settings.php and uncomment this

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

this file should be in web/sites/default/settings.local.php so copy and rename the example.settings.local.php located at web/sites to web/sites/default/ as settings.local.php

Step 2

Although is kind of "safe" to have drupal generate a config/sync path for you in web/sites/default/files folder

$settings['config_sync_directory'] = 'sites/default/files/config_D1ZE3yYjDCyT-b50-edPMg4Q-bqBMlQr288CtvG3gHpuIEth6oW3rdwx4_jxzeUwBsA8dC3p5A/sync';

why not to have full protection for the config/sync folder by adding the path to your web root installation like this

$settings['config_sync_directory'] = '../config/sync';

So now our config/sync folder is in our web folder. This is way much safer.

Step 3 (if you use Kint)

After installing drupal/devel

composer require drupal/devel;drush en -y devel;

open your settings.local.php file and add this at your end of the file

include_once(DRUPAL_ROOT . '/modules/contrib/devel/kint/kint/Kint.class.php');
// If debugging is very slow or leads to WSOD reduce the number
// of levels of information shown by Kint.
// Change Kint maxLevels setting:
if (class_exists('Kint')){
  // Set the maxlevels to prevent out-of-memory. Currently there doesn't seem to be a cleaner way to set this:
  Kint::$maxLevels = 4;
}

With this setting we make sure that we won't run out of php memory while developing our awesome stuff.

Step 3 (if you don't use Kint)

With drupal 9 and symfony's default Variables Dumper (dump) you might want to skip the Kint development option and go with the default Symfony's  Development way. So instead of using ksm($entity) for example you can use dump($entity).

Drupal Devel Settings page

Step 4

In settings.local.php you will find this option somewhere in the beginning of the file

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

Do not use that dev services yml file but make a copy instead with this name:

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

development.local.services.yml not development.services.yml. If you use development.services.yml everything will work fine until you run your next composer update or composer require. After that development.services.yml will reset to default settings. So your twig development settings will be deleted.

Now open development.local.services.yml and apply the twig devel options like this.

# 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
services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

we just added this:

  twig.config:
    debug: true
    auto_reload: true

Step 5

Go to /admin/config/development/performance and disable all the caches (css & js).

That's it!

best practices