Drupal has a unified way of storing your site's configuration. Its configuration system allows for a very effective development workflow, when leveraging tools like Drush and Git. It's not limited to developers however. The Drupal administrative UI provides forms for managing your site's configuration, too.
In this series of tutorials you'll learn all about the new configuration system in Drupal. You'll learn key concepts in configuration management and important skills like how to move configuration from local development to production.
In these tutorials, we'll use command-line tools like Drupal Console, Drush, and Git as well as GUI tools as an alternative toolchain for tasks like cloning a site and importing and exporting site configuration.
By the end of this series, you will understand how you can manage configuration between instances of your site.
To learn how to leverage configuration data in a module, see the tutorial series, Configuration Entities.
Drupal's configuration system helps to solve the problem of moving changes in configuration from development to production. It does this in two ways: by providing a unified way to store configuration and by providing a process by which configuration changes can be imported and exported between instances of the same site. The configuration system is the result of work completed within the Configuration Management Initiative (CMI).
In this introduction, we'll provide:
- An overview of Drupal's configuration system
- Key concepts that you should know about
Before we start synchronizing configuration, let's take a look at the default, out-of-the-box file location for staging and synchronizing configuration. Then we'll walk through how to change that directory to a location outside of our project's docroot and update settings.php appropriately.
In this tutorial, we'll cover:
- The default location of the configuration sync directory
- How the configuration sync directory is secured
- How to change the location of the sync directory
Before you can get started synchronizing configuration between instances of your site, you'll need to create a new instance or "clone" of your Drupal site.
By the end of this tutorial, you should know:
- Why it's necessary to clone your site if you want to manage configuration between environments
- How to find your site's universally unique identifier (UUID)
- What to consider when setting up a directory structure for your project
- How to clone a Drupal site
The configuration system in Drupal was designed to manage and sync configuration between instances of a Drupal site. So before configuration management can be useful, we must have another instance—or clone—of our Drupal site. In this lesson, you will learn:
- Why cloning a Drupal site is necessary in order to manage configuration
- How to clone a Drupal site using tools that have a graphical user interface (GUI)
If you prefer using using web-based or GUI tools rather than command line tools such as Drush and Git, then this lesson is for you.
The Configuration Manager module gives you as an administrator the ability to import and export configuration items on different instances of a Drupal site using an graphical user interface. In this tutorial, we'll take a tour of the Configuration Manager and the administrative interface it provides.
By the end of this lesson you will be able to:
- Access administrative pages for Import, Export, and Synchronize
- Find and configure permissions for Configuration Manager
- Identify the 3 primary actions of configuration management and how to perform them using the UI
While the administrative UI for Configuration synchronization certainly provides a simple and effective means to export and import configuration, it is by no means the preferred method. The Drush command line utility provides the same functionality without the need for a web interface or the need to log in.
There are some administrative UI tools for managing configuration, but some tasks can only be completed with Drush. As a site administrator, you will find Drush an indispensable tool for managing configuration between instances of the same site. Furthermore, Drush includes integration with Git in certain commands, enabling you to create a configuration workflow with Drush that also uses best practices in version control.
By the end of this lesson you should be able to:
- Get the status of a site's configuration
- List configuration on a site
- View configuration objects
- Set values for a specific key inside a configuration object
- Edit a configuration object in active configuration without needing a configuration form
- Integrate a Git workflow with Drush
Using Drush to work with the Drupal Configuration System is straightforward when working locally. Navigate to the directory containing your site, then issue whatever Drush command you need.
Things become more complicated when multiple environments become involved. Often, a configuration change will need to be made on the production ("live") site and then need to be persisted to a Git repository later. When this occurs, Drush once more provides a solution in the form of the
Note: Drush 8 and the latest version use different methods and file types for configuration files. This tutorial will demonstrate methods that are compatible with the latest version of Drush with notes related to Drush 8.
Drupal creates a line of separation between what is content and what is configuration. The line is such that content is stored only in the database, whereas configuration is maintained by the configuration management system. While cached to the database for performance reasons, configuration can be thought of primarily living in the sync directory as a series of flat files.
This sounds like a perfectly clear distinction in theory, but there are several times where interdependencies appear between content and configuration. Understanding the key places where these interface can help prevent confusion and "disappearing" settings due to a lack of understanding.
Not every environment or copy of a site you may be working on will be created equally. You may want to enable logging on a development site or need to use different API keys depending on the environment. But you also need to make sure that your instance-specific configuration overrides don't make it into the database, mistakenly get exported, or compromise security.
In this tutorial, you will learn how to:
- Override the global
$configarray in settings.php (or settings.local.php)
- Retrieve overridden (immutable) configuration (read-only mode)
- Retrieve original (mutable) configuration for updating (read/write mode)
- Set dynamic values for configuration instead of overriding values
Modules like Devel or Stage File Proxy offer key advantages when developing locally, but should never be enabled on a production site. This poses a problem for Drupal as which modules are enabled is a configuration. Compounding this problem is the configuration provided by these modules, as well as key configuration that must be set differently locally compared to production.
Fortunately, the Configuration Split module provides a means to accomplish all of these goals. Once set up, configuration can be exported in one or more "splits", enabling you to target different configurations for different environments or situations.
When automating the deployment of a Drupal site, it's critical to have a good understanding of the configuration management workflow in order for deployments to be consistent and successful.
When working on configuration in a module, whether as part of a migration that uses Migrate Plus configuration entities, or while developing custom configuration entities, you'll often need to re-import the configuration stored in the .yml files of the modules config/install/ or config/optional/ directories. This is tricky though, because Drupal only reads in those default configuration settings when the module is first enabled. So any changes you make to those files after the module has been installed will not be reflected without these workarounds.
Knowing how to do this can improve the developer experience of adding (or debugging) the default configuration that's provided with a module. Or for anyone using Migrate Plus configuration entities as part of a migration.
In this tutorial we'll:
- Learn about the Configuration Development module
- Look at how you can use Drush to perform a partial configuration import
- Write an implementation of
hook_uninstall()to remove a module's configuration when it's uninstalled
By the end of this tutorial you should be able to re-import the configuration provided by a module without having to uninstall and then reinstall the module.