Creating a simple split configuration: Dev modules only in dev environments

Last updated on
25 September 2023

This documentation needs work. See "Help improve this page" in the sidebar.

This page refers to Config Split 1.x and should be updated. See #3269656

In the simplest scenario, we want to enable a few extra modules on development environments (Devel, Kint, Stage File Proxy, Views UI, etc.), but not have these modules enabled on production.

Note! If you do not want to share the configuration of the development modules, you can use the Drupal core functionality from version 10+ onward using the $settings['config_exclude_modules'] setting. Learn more here: https://www.drupal.org/node/3079028.

With Configuration Split we'll need to create a new Configuration Split Setting for the development environments.

But first:

  1. Ensure that you have no config overrides. From the command line, you can accomplish this by using drush config:status or turning on the Configuration Manager module and inspecting "/admin/config/development/configuration" for overrides.
  2. Enable Configuration Split module in a local environment.
  3. Export config, commit and deploy to the live environment as you usually would.
  4. Enable and configure all your development modules in the local environment.

Create a Configuration Split

Navigate to:

Administration » Configuration » Development  » Configuration Split Setting » Add configuration split setting

Or go to /admin/config/development/configuration/config-split/add

Config split screenshot 1

Screenshot  1 - Creating a new split configuration

Config split screenshot 2

Screenshot  2 - Creating a new split configuration

There’s a few things that aren’t covered in the help text but are important to note:

  • Keep the Machine name the same as the Folder.
  • The Folder is relative to the Drupal root (it does say this in the help text, I just skimmed right past it the first time.  Often people use "../config/sync" to avoid storing config under the docroot, in that case you might use "../config/config_dev" for the split configuration).
  • Active should be checked when you make your initial export and/or are editing your split. If you mark the split as inactive and then export config, whatever config changes you make will be exported to the general config/sync directory and not split out. After exporting your split, you'll want to make it inactive by default and override that in settings.php to enable the split conditionally (more on this later)

Select your development modules from the list in Complete Split.  Their configuration will not be included in the main configuration. (Ignore 'Configuration items' unless you want to be more precise).

  • Save the form.
  • Create the directory.
  • Export your configuration.  (The split configuration files will be created, even though drush config:export only mentions the main directory.)

Be sure to read the page on CLI Integration.

Enabling the split configuration in development environments, but not production

Remember that active checkbox from above?  That’s what defines whether the configuration split is enabled or not.  It is important to note that the active checkbox needs to be checked for config export to work as you would expect. The trick is that we want to have that setting disabled by default and enabled only on certain environments when config gets imported. This can be done in settings.php:

// Use development config in dev environments. 
if (/* Some logic to determine that the current environment is staging or production */) {
  $config['config_split.config_split.config_dev']['status'] = FALSE;
}
else {
  $config['config_split.config_split.config_dev']['status'] = TRUE;
}

Make sure to use the same machine name as you configured previously and make sure to clear cache with each change.

Development Workflow

You don’t need to use any of the following Drush or Drupal Console commands, you can still use the UI at:

Administration » Configuration Development » Synchronize

Pulling a database from production to a dev environment

The first step is to get the database.  How to do that depends on your hosting and local environments.  Then import and update configuration.

# Clear caches
$ drush cache-rebuild

## Then import the development configuration only. 

# If you are using drush 8 or earlier:
$ drush config-split-import config_dev

# If you have drush 9 or later, use the newer command format:
$ drush config-split:import config_dev

## Check for config overrides from production, and get those back into code.

# If you are using drush 8 or earlier:
$ drush config-export

# If you have drush 9 or later, use the newer command format:
$ drush config:export

Pushing configuration from dev to production

In the dev environment

After you've made some configuration changes:

# Export the configuration.  
# This will update both config and config_dev.

# If you are using drush 8:
$ drush config-export

# If you have drush 9 or later, use the new command format:
$ drush config:export

In the pre-production / production environment


# Import configuration.
# This will import config; and if active in settings.php, config_dev

# If you are using drush 8:
$ drush config-import

# If you have drush 9 or later, use the new command format:
$ drush config:import

Additional Info

See this post in the Documentation issue queue:
https://www.drupal.org/node/2891555#comment-12154147

Help improve this page

Page status: Needs work

You can: