Config Management Basics Training Class Notes

Image
Configuration Management Training

Blog Categories

Command Line

We will work mostly on the command line for this training to install and enable modules, as well as importing and exporting configuration. If a task can also be done via the Drupal UI I will also show that. If you do not feel comfortable with the Command Line or have questions on it’s use for this training.

Local Setup

If you would like to follow along with the live demo portion of the training you will need a local development environment setup. It doesn’t matter what kind of local setup you have (lando, DDEV, MAMP, etc). I will be using Lando with the Drupal Recommended Project (https://github.com/drupal/recommended-project).

Below I have included my basic setup steps. Feel free to follow them or use your own or just follow along with the screen share. This is not required to participate in the training.

  1. Create temporary directory (I called my startup)
mkdir startup
  1. Cd into directory
cd startup
  1. Initiate a Lando environment.  Assuming you already have lando installed, if not go to https://docs.lando.dev/basics/installation.html. The below will prompt you to set up your local work through the prompts. 
lando init
Image
Lando App Codebase Selection Prompt
Image
Lando Recipe Selection Prompt
Image
Lando Set Webroot Prompt
Image
Lando App Title Prompt
  1. Start Lando
lando start
  1. Run the composer command to install Drupal Recommended Project. Note: my_site_name_dir can be whatever you want your directory name to be. 
lando composer create-project drupal/recommended-project my_site_name_dir
  1. Stop lando
lando stop
  1. Move your working directory (if you want). Step one would be to move .lando.yml into new my_site_name_dir from above.
mv .lando.yml my_site_name_dir

Then let’s move our working directory up one (or wherever you want)

mv my_site_name_dir ../

Check to make sure no other files are in the startup dir

cd ../

Then remove your startup directory

rm -rf startup

You should now have your my_site_name_dir where you want it.

  1. Let’s get our local up and running and install Drupal
cd my_site_name_dir

lando start

After Lando starts you should see the following.

Image
Lando Start Completion Vitals

Go to the URL provided for your local setup and go through the Drupal Install. Note: Using the Standard Drupal install profile at setup is fine for this training.

For more information on installing Drupal via composer, check out the drupal.org documentation. 

https://www.drupal.org/docs/develop/using-composer/using-composer-to-install-drupal-and-manage-dependencies
 

Let's Play with Config Mangagment & Config Split

Configuration Management

  1. Let’s start by getting familiar with the Configuration Management user interface (UI) and the features that come form Drupal core. 
  • Review the Drupal Core UI for Configuration Sync / Import / Export found at /admin/config/development/configuration
Image
Drupal Configuration Management Screen
  1. We are going to configure our site to use Configuration Management
  • Change the default location for configuration storage in your sites settings.php file.
$settings['config_sync_directory'] = '../config/common';
  • The above directory doesn’t exist so we will have to make it.
mkdir config

cd config

mkdir common
  • Test our first export
lando drush cex 

Or the full command

lando drush config-export
  1. Let’s play with Configuration Export and Import
  • Export Configuration
    • We are going to show this by installing our favorite module Admin Toolbar
lando composer require drupal/admin_toolbar

lando drush en admin_toolbar
  • We will show the basic changes in the Drupal UI
    • Look at /admin/config/development/configuration and view differences in the config.
Image
View Drupal Config Management Changes
  • Above is an example of a config change. Review Active vs Staged Configuration.
  • Let's export the current configuration (with the command above)
  • Let's Import Configuration
    • Now that we have our exported configuration make some changes and import configuration instead.
lando drush cim 

Or

lando drush config-import

Notice how your changes get reverted after the import.

Config Split

  1. Let’s start off by installing and enabling the Config Split Module.
lando composer require drupal/config_split

lando drush en config_split
  1. Now we need to set up some folders to store our split configuration in. 
cd config/

mkdir prod

mkdir dev
  1. Using the Drupal UI we can configure our splits 

    Image
    Configuration Management Screen
    Image
    Config Managment Complete Split
    Image
    Config Split Conditional Split
  2. After you have setup your split we can enable our Dev split with the following in our settings.php file
$config['config_split.config_split.my_split']['status'] = TRUE;

You should setup one of the above for each split you have. Note only one should be enabled (TURE) at a time.

  1. To switch between splits you can set the desired split to TRUE in your settings.php file. After changing the settings in settings.php be sure to do the following.
lando drush cr && lando drush cim

Or

lando drush cache:rebuild && lando drush config-import
  1. Now you can play with Config Split Try the following.
  • Add a Conditional Split for system.site
    • Now update your Site Name
  • Add a Complete Split for the Devel Module
    • Install Devel for the Dev Split using the following command
lando composer require drupal/devel

Note: Be sure to be in the split you want to add the module to. It will make your life easier.

Use Cases

The following are just some of the many use cases for Config Split.

  • Setting different Google Analytics ID's for dev, stage, and prod.
  • Disabling or Enabling DB Log or Sys Log depending on environment
  • Sometimes creating feature splits is a good idea. Feature splits can be used when features are needed for selected environments. 

    Image
    Feature Split Example
    Image
    Feature Split Code Example

Resources

Drupal Recommended

Lando Install

Drush

Modules

Config Split

Admin Toolbar

Devel