How To Set Up Drupal 8 Configuration Management

Submitted by Johnny Martin on Tue, 04/24/2018 - 16:50

After years of manually making database configuration changes between servers on Drupal 7, I never quite grasped Drupal 8's new Configuration Management. I knew that Drupal 8 had some sort of file-based configuration import/export, and that settings.php required a config directory to be configured, but it seemed useless/broken. After chatting to the good people in Drupal Twig, they revealed how easy and useful it was.

Drupal's Configuration Management allows the import and export of site settings, content type configurations, block settings (not block content,) image styles, and other configuration-based database records.

By default, Drupal creates a sync folder in your files directory on installation. The kicker here is that the sync folder is inside of the default .gitignore on new Drupal installations, so it makes moving your site's configuration around a manual process. A standard way of resolving this is placing the config file outside of the website root, but still keeping it inside of the git repo. If you're using a composer-based Drupal installation like Drupal Project, a great place to put the config is in the repo root, and reference it in your settings.php like this: `$config_directories['sync'] = '../config/sync';`

Once your configuration file is inside of your git repo, you'll be able to call some simple drush commands to import and export the config. `drush cex` will export all of your site's config into the sync directory, and `drush cim` will import it again once you've pushed the config to the server.

Make sure before you start this process that your databases between your servers or dev environment are in sync. Once everything's set up, stop making configuration changes in staging and production! It'll make your life a lot easier and save time.

A helpful note: If you don't want to manage webform configuration changes from the sync files, check out the Config Ignore module.

Thanks to @markconroy in Drupal Twig for helping me figure this out.