Including Custom Settings In Drupal Using DDEV


When DDEV launches Drupal for you it creates settings.ddev.php files. This file is added as an include to the settings.php file that Durpal generally uses.  Scroll to the bottom of your settings.php file and you will see the code that DDEV has had to append there after your first installation. 

In my scenario I wanted to provide specific settings for the location of my config directory. Though there is documentation on the Internet already about how to do this I found it somewhat unclear, so I hope this post clarifies it. 

The newly created settings.ddev.php is not a full settings file it is just settings that DDEV needs like the database you are using for your local environment that is probably not the same as your production environment.  So, what you can do is add another settings file first. Adding settings.local.php and including it before settings.ddev.php will make sure your settings are used. 

It will look something like this.

//Add local settings file to be included
if (file_exists($app_root . '/' . $site_path . '/settings.local.php') && getenv('IS_DDEV_PROJECT') == 'true') {
  include $app_root . '/' . $site_path . '/settings.local.php';

// Automatically generated include for settings managed by ddev.
if (file_exists($app_root . '/' . $site_path . '/settings.ddev.php') && getenv('IS_DDEV_PROJECT') == 'true') {
  include $app_root . '/' . $site_path . '/settings.ddev.php';

This method works well if you want to set a few settings, for example where config files will be stored. I would not recommend it for trying to define the entire config for DDEV there are options for that. Both the documentation and this post explain how to do that.