LocalGov Drupal is an opensource Drupal distribution being built and maintained by UK Councils and Drupal developers. Its rationale: to pool knowledge resources to build a better publishing platform for local governments.

LocalGov's documentation explains how to set up LocalGov Drupal using Lando, a docker based tool to set up local development environments.

At TrainingCloud we prefer DDEV-local, a tool similar to Lando. Even though the company behind DDEV has announced their shutdown on May 15 2021, DDEV itself shows no signs of calling it quits.

This article assumes you've already set up DDEV-local itself. If you haven't, follow the DDEV-local installation instructions first and then continue reading this article.

For the purposes of this article:

  • we'll name our project Weatherfield
  • we refer to the DDEV-local tool simply as DDEV
  • we place all our projects in our local ~/projects/ directory

Step 1: Fetch the LocalGov Drupal source code

In ~/projects:

$ composer create-project --stability dev localgovdrupal/localgov-project weatherfield --remove-vcs

Step 2: Set up a DDEV instance

In ~/projects/weatherfield:

$ ddev config

When prompted by DDEV, provide the following values:

  • site name: weatherfield (= default)
  • docroot location: web (= default)
  • project type: drupal8 (= default)

site name is used as part of your local site's hostname
docroot location is where the actual Drupal site is located
project type tells DDEV how to configure the local hosting environment

Step 3: Tell Drupal to load DDEV settings instead of Lando settings

The Drupal settings file at /sites/default/settings.php that comes with LocalGov Drupal loads `settings.lando.php' at the very end.

To replace that block at the end with the following:

 * Load local development override configuration, if available.
 * Use settings.local.php to override variables on secondary (staging,
 * development, etc) installations of this site. Typically used to disable
 * caching, JavaScript/CSS compression, re-routing of outgoing emails, and
 * other things that should not happen on development and testing sites.
 * Keep this code block at the end of this file to take full effect.
if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
  include $app_root . '/' . $site_path . '/settings.local.php';
elseif (file_exists($app_root . '/' . $site_path . '/settings.ddev.php') && getenv('IS_DDEV_PROJECT') == 'true') {
  include $app_root . '/' . $site_path . '/settings.ddev.php';

→ this will try to load your custom local settings file, if you have one, and fall back to settings.ddev.php, if you have one.

Step 4: Customise a few DDEV settings

In .ddev/config.yaml:

  • If your port 80 is already in use by another webserver or DDEV environment, DDEV will show an error when you try to start. When this happens, change the router (webserver) port:
router_http_port: "8080"

→ choose any number, by convention in the 8000-8999 range

  • DDEV automatically recreates ddev.settings.php after every restart. We personally don't like this because we tend to add more custom settings to sites/default/settings.ddev.php, so we disable this feature:
disable_settings_management: true

In web/sites/default/settings.ddev.php:

  • set Drupal's configuration management directory to ../config/sync, LocalGov Drupal's default config directory:
$settings['config_sync_directory'] = '../config/sync';
  • set maximum error reporting and verbose error logging:
 * Error reporting.
 * As a developer it is useful to see all errors. If the site you are working
 * on has a lot of notice errors and you aren't able to fix them you can
 * suppress them by modifying E_ALL in error_reporting to:
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

 * Show all error messages, with backtrace information.
 * In case the error level could not be fetched from the database, as for
 * example the database connection failed, we rely only on this value.
$config['system.logging']['error_level'] = 'verbose';

Step 5: Start DDEV

In ~/projects/weatherfield:

$ ddev start

Step 6: Install LocalGov Drupal from the command line

In ~/projects/weatherfield:

$ ddev exec drush si localgov -y

Step 7: Launch project in browser

In ~/projects/weatherfield:

$ ddev launch

→ opens a new tab in your default browser and loads your new LocalGov Drupal site. Imagine what you can do with all the time you saved by not having to copy/paste the project link into your browser by hand :)

If everything went well, you should see your new LocalGoc Drupal site waiting for you.