Working with file system based configuration
Note that by default, Drupal stores configuration management data in the database. To enable a file-based workflow, you must modify both settings.php
and services.yml
.
This must be done before installing Drupal, as switching back to database-based configuration after enabling file-based storage is complex. If you need to enable configuration in files after site installation, you must first export your configuration and save a copy in the active config directory before enabling file-based config management.
Note: You must have separate active and staging directories (as shown below)—the configuration import step is still required even with a file-based workflow. See this issue: the file system-based workflow doesn't correctly install/uninstall modules without the configuration import step.
1. Open settings.php
and locate the “Active configuration settings” section.
2. Uncomment the line starting with $settings['bootstrap_config_storage']
to enable file storage for configuration.
Ensure the line reads:
$settings['bootstrap_config_storage'] = array('Drupal\Core\Config\BootstrapConfigStorageFactory::class', 'getFileStorage');
3. Add the following code to settings.php
(adapted from this Drupal.org comment):
$config_directories[CONFIG_ACTIVE_DIRECTORY] = 'PATH_OUTSIDE_WEB_ROOT/config/active/'; $config_directories[CONFIG_STAGING_DIRECTORY] = 'PATH_OUTSIDE_WEB_ROOT/config/staging/';
Save the file.
4. Open the services.yml
file in sites/default
and add the following code (from this Drupal.org comment):
services: config.storage: class: Drupal\Core\Config\CachedStorage arguments: ['@config.storage.active', '@cache.config'] config.storage.active: class: Drupal\Core\Config\FileStorage factory: Drupal\Core\Config\FileStorageFactory::getActive
5. Copy the configuration files (.yml
) from the active folder of the source site to its staging folder.
6. Use a tool like rsync
, git
, ftp
, or scp
to copy the contents of the source staging folder to the destination staging folder.
7. On the target website, go to /admin/config/development/configuration
.
8. Click Import All.
Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.