Specbee: How to split configurations across different sites on Drupal 9

How to split configurations across different sites on Drupal 9
Karishma
06 Jul, 2021

Configuration management is one of the greatest features introduced in Drupal. It enables developers to easily push configuration changes from their development environment to staging, and then to production environments. There are cases where certain configurations need to be enabled only on certain environments. For example, modules like Devel, Kint, Views UI, are enabled only on development environments, but we do not have these modules enabled on production. 

Fortunately, the Configuration Split module provides a means to accomplish all of these goals by keeping configurations into a separate directory so we can import it in a certain environment. And the Drupal 8 Configuration Split module is also supported in Drupal 9! In this article, you will learn how to split configurations across different websites using this amazing module.
Split Configuration

Setup and using the Configuration Split module

Installing the Drupal Configuration split module is like installing any other contributed module. Use composer to install it since it automatically installs all of the necessary dependencies. Open the terminal, within the project and enter the command.

$ composer require drupal/config_split

Create the split configuration

Once installed and enabled, we can create one or more “splits” to keep our configuration file in a separate folder.

  • Go to Admin > Configuration > Development > Configuration Split Settings
  • Click Add Configuration Split Setting
  • Enter a Label.
  • In the folder field, enter the folder name relative to the Docroot.
../config/dev_split

Make sure the machine name of your split is the same as the folder name.
Dev Split 

  • Choose the module you want to split. In our case – the Devel Module.
  • Add your development modules setting files to the config split. In this case, we are going to completely split the configuration for Devel.

Complete Split 

  • Click Save.

Activate a Split

Once the split is created, it needs to be activated in order to carry out a split. The Configuration Split module does not provide a UI for this purpose, but instead we can modify our settings.php file to activate the split:

$config['config_split.config_split.dev_split']['status'] = TRUE;

Where, dev_split is the machine name of the split we created earlier.

Now, export your configuration using drush cex. You should see that your development modules have been exported to the dev_split directory.
Dev Split

  • For our Development split, we need to have it activated in the development environment, but not in production. To do so, we add the following to our settings.php on our development environment.
$config['config_split.config_split.development']['status'] = TRUE;
  • For the Production site we won’t add this code in the settings file, or we can also disable it explicitly by using below code:
config['config_split.config_split.development']['status'] = FALSE;
Shefali ShettyApr 05, 2017

 


Go to Source
Author: