After implementing some larger enterprise Drupal 8 websites, I would like to share some insights, how to solve common issues in the deployment workflow with Drupal 8 CMI.
Introduction to Drupal CMI
First of all, you need to understand, how the configuration management in Drupal 8 works. CMI allows you to export all configurations and its dependencies from the database into yml text files. To make sure, you never end up in an inconsistent state, CMI always exports everything. By default, you cannot exclude certain configurations.
If you change some configuration on the live database, these configurations will be reverted in the next deployment when you use
This is helpful and will make sure, you have the same configuration on all your systems.
How can I have different configurations on local / stage / live environments?
Sometimes, you want to have different configurations on your environments. For example, we have installed a “devel” module only on our local environment but we want to have it disabled on the live environment.
This can be achieved by using the configuration split module.
What does Configuration Split?
This module slightly modifies the CMI by implementing a Config Filter. Importing and exporting works the same way as before, except some configuration is read from and written to different directories. Importing configuration still removes configuration not present in the files. Thus, the robustness and predictability of the configuration management remains. And the best thing is: You still can use the same drush commands if you have at least Drush 8.1.10 installed .
Configuration Split Example / Installation Guide
Install config_split using composer. You need need at least “ 8.x-1.0-beta4” and > drush 8.1.10 for this guide.
composer require drupal/config_split "^1.0"
Enable config_split and navigate to “admin/config/development/configuration/config-split”
drush en config_split -y
Optional: Installing the chosen module will make the selection of blacklists / greylists way more easier. You can enable chosen only on admin pages.
composer require drupal/chosen "^1.0"
I recommend you to create an “environments” subfolder in your config folder. Inside this folder you will have a separate directory for every environment:
Now you can configure your environments:
The most important thing is, that you set every environment to “Inactive”. We will later activate them according to the environment via settings.php
Here is my example where I enable the devel module on local:
Activate the environments via settings.php
This is the most important part of the whole setup up. Normally, we never commit the settings.php into git. But we have a [environment]-settings.php in git for every environment:
settings.php (not in git) variables-dev.php (in git and included in the settings.php of dev) variables-live.php (in git and included in the settings.php of live) settings.local.php (in git and included locally)
You need to add the following line to the variables-[environment].php. Please change the variable name according to your environment machine name :
// This enables the config_split module $config['config_split.config_split.dev']['status'] = TRUE;
If you have done everything correctly and cleared the cache you will see “active (overriden)” in the config_split overview next to the current environment.
Now you can continue using
drush config-import -y drush config-export -y
and config_split will do the magic.
How can I exclude certain Config Files and prevent them to be overridden / deleted on my live environment?
The most prominent candidates for this workflow are webforms and contact forms . In Drupal 7, webforms are nodes and you were able to give your CMS administrator the opportunity to create their own forms.
In Drupal 8 webforms are config entities , which means that they will be deleted while deploying if the yml files are not in git.
After testing a lot of different modules / drush scripts, I finally came up with an easy to use workflow to solve this issue and give CMS administrators the possibility to create webforms without git knowledge:
Set up an “Excluded” environment
First of all, we need an “excluded” environment. I created a subfolder in my config-folder and added a .htaccess file to protect the content. You can copy the .htaccess from an existing environment, if you are lazy. Don't forget to deploy this folder to your live system before you do the next steps.
Now you can exclude some config files to be excluded / grey-listed on your live environment:
Set the excluded environment to “Inactive” . We will later enable it on the live / dev environment via settings.php.
Enable “excluded” environment and adapt deployment workflow
We enable the “excluded” environment on the live system via variables-live.php (see above):
// This will allow module config per environment and exclude webforms from being overridden $config['config_split.config_split.excluded']['status'] = TRUE;
In your deployment workflow / script you need to add the following line before you do a drush config-import:
#execute some drush commands echo "-----------------------------------------------------------" echo "Exporting excluded config" drush @live config-split-export -y excluded echo "-----------------------------------------------------------" echo "Importing configuration" drush @live config-import -y
The drush command “ drush @live config-split-export -y excluded ” will export all webforms and contact forms created by your CMS administrators into the folder “excluded”. The “drush config-import” command will therefore not delete them and your administrators can happily create their custom forms.
Benefit of disable “excluded” on local environment
We usually disable the “excluded” environment on our local environment. This allows us to create complex webforms on our local machine for our clients and deploy them as usual. In the end you can have a mix of customer created webforms and your own webforms which is quite helpful.
The CMI is a great tool and I would like to thank the maintainers of the config_split module for their great extension. This is a huge step forward making Drupal 8 a real Enterprise CMS Tool.
If you have any questions, don't hesitate to post a comment.