Changing the storage location of the sync directory

Last updated on
10 January 2024

By default, Drupal places the configuration sync directory within the site's files directory, using a hash as part of the directory name, thus sites/default/files/config_HASH. The HASH is a pretty long string of random characters. This makes configuration more difficult (but not impossible) to be accessed over the web. The sync directory location can be changed after installation.

On production sites, and if your account has permission to do so, it's a good idea to move the configuration sync directory outside of the webroot entirely. As your sync directory should be under version control, this means having your version control repository's root be one level higher than your webroot.

On local development sites, you may want to be able to access the config files more easily, and so move the directory to something like sites/default/sync.

To move the directory, open up your settings.php file. At the end of the file, Drupal's installation process will have written a line specifying the location of the sync directory within sites/default/files/config_HASH.

If you want to move this directory, let's say to sites/default/sync, update the $settings variable like this:
$settings['config_sync_directory'] = 'sites/default/sync';

If you want to move the folder outside of your webroot, you can use something like
$settings['config_sync_directory'] = '../config/sync';
where the config directory has the same parent directory as your webroot, and the sync directory exists within the config directory.

Note that, by default, DDEV will set your sync directory location to sites/default/files/sync if it is not set in settings.php. It does this via this entry in its settings.ddev.php file:

// Set $settings['config_sync_directory'] if not set in settings.php.
if (empty($settings['config_sync_directory'])) {
  $settings['config_sync_directory'] = 'sites/default/files/sync';
}

That's it! Now whether using the Configuration Management UI or Drush based workflow, the correct sync directory is being used.

Failure to have a sync directory can result in the following message in your PHP error log:
Uncaught PHP Exception Exception: "The configuration directory type 'sync' does not exist"

Syntax differences prior to Drupal 8.8.0

Prior to Drupal 8.8.0 the sync directory is defined in $config_directories and not $settings, and so the settings.php file should be updated.

Simply change from:

$config_directories['sync'] = 'foo/bar';

to

$settings['config_sync_directory'] = 'foo/bar';

Help improve this page

Page status: No known problems

You can: