Managing Drupal 8 site configuration with Git

This post is about:

  • Drupal 8.0.0+


In the previous post I described how to set up Drupal 8 website from scratch using Drupal Composer template. Now that such a website is in place, here are some notes on managing configuration syncronisation between the two instances (local and production) of the same website.


Setting up config syncronisation for the first time

Firstly, you need to move your config folder outside of web root. To do so in your local environment:

1. Create a folder config/sync in the root of the project (one level above /web).

2. Make sure the new folder is writable:

chmod 775 config/sync

3. Modify settings.php:

$config_directories = array(
  CONFIG_SYNC_DIRECTORY => '../config/sync’,

4. Delete the old sync folder.

5. Add the new folder to Git.

6. Commit changes to Git and push them to external repo.

7. Pull the changes from external repo on production (or another environment you want to sync with) and make sure the folder exists there with all the proper permissions.

Once this is done, you can sync your config between the two environments via Git following the steps below.


Syncronising configuration between two environments

1. On local environment, from Drupal root (/web folder) run:

drush cex -y

You will see:

Configuration successfully exported to ../config/sync.

2. Commit those changes and push to external repo.

3. On production pull changes from the external repo.

4. On production from your Drupal root (/web folder) run:

drush cim -y

You will see:

Import the listed configuration changes? (y/n): y
Cache rebuild complete.                                                [ok]
The configuration was imported successfully.                           [success]

That's it!


Typically, you would do changes on your local environment and then export them and sync up to production.

If some config changes do occur on production, run 'drush cex -y' there. Review the exported changes carefully and decide if you want to save them (and bring them down to local). If you do want to keep them - commit to git repo. Then pull on local and import.

To avoid commit conflicts it might be easier to manually repeat production changes on local via UI. And then export and sync them per normal process.

For more information:


Thanks Alex Pott for answering my questions while I was figuring this out.


Other posts in the series: