Module Development

How to Override Configuration for Drupal 8, 9, 10, and 11

Not every environment or copy of a site you may be working on will be created equally. You may want to enable logging on a development site or need to use different API keys depending on the environment. But you also need to make sure that your instance-specific configuration overrides don't make it into the database, mistakenly get exported, or compromise security.

In this tutorial, you will learn how to:

  • Override the global $config array in settings.php (or settings.local.php)
  • Retrieve overridden (immutable) configuration (read-only mode)
  • Retrieve original (mutable) configuration for updating (read/write mode)
  • Set dynamic values for configuration instead of overriding values

Drupal Site Administration