Configuration Split in Drupal 8 and 9. How to Add Config To Your Live Environment
How do you enable that module for just the live site again?
Let’s first start off with understanding what the Configuration Split module does. In simple terms, it allows you to have different site configurations for your different environments. For example, you want to turn off the Views UI module on your live site. Or you want to turn off your Google Analytics module on your local, dev, and test environments but still have it active on your live site.
There are so many great articles on setting up configuration split. Here are a few good ones that I suggest reading to get you caught up to speed.
- Drupal 8 Configuration Management with Config Split by Daggerhart Labs. This is a good article if you are hosting on Pantheon as it helps you with the code for config split to determine what environment you are on with their hosting.
- Config Split: A Guide to Conditional Configuration in Drupal 9 by the Mike Madison. Mike is an OG in the Drupal community and was the former maintainer for Acquia’s Build and Launch Tools (BLT). This article provides a nice little example for setting configuration in four different environments and its Drupal 9 specific.
- Set up and Use Configuration Split Module for Drupal 8, Drupal 9 by Drupalize.me a premier Drupal training site that has been around the Drupal Community for Years.
So how do you test and or create new configuration settings for your live environment while working on your local computer?
In other words, say that you have already set up your config-splits a few months ago but now your client wants to add email support using the SMTP module but you only want this enabled on the live site so you don’t accidentally send out an email from your local site to 1000’s of users. ps — I have done it before Ouch :)
Well in order to add to the live configuration you need to enable the live config split. The natural first step is to go to the config-split UI and disable the develop configuration and enable the live config. Click Click Click. But nothing. Such a simple thing but why in the heck are you not able to enable the live configuration?
The settings.php Environment Gotcha
One thing all of these tutorials have in common is that they show you how to set the active and inactive config-splits in your settings.php. For some servers, the code is slightly different but the idea here is that Drupal needs to somehow know what environment you are on in order to import the right configuration.
Yep! That darn settings.php
file. The reason you cannot activate the live configuration settings in the UI is that the settings.php
file overrides the UI click clicks. So you need to go to your file and either temporarily comment out that code or just reverse the logic. So here is what I do.
- Reverse the logic in the
settings.php
file. For me, I just have to switch out a ! in my code so that my dev and live environments are reversed. drush cr
— Cache rules everything around me — Clear itdrush cim
Load all of your config from the live environment into your local- Enable my new SMTP module.
- Edit the live config split and check the box next to the SMTP module
drush cex
— configuration exportgit checkout settings.php
so that my file reverts back to my old settingsdrush cr
— you know the drill clear that cachedrush cim
This disables the SMTP module and loads just the development modules on your core- git commit my changes
I then check my setting by doing a drush csim live
. This command imports the settings from the live config. You can also check your config directories manually or with a git status
to ensure there are new files in both of your dev
and live
directories.