Drupal configuration management: local to live, safely

You add a new field to a content type on your laptop, adjust a View, and tweak a few settings. Then you log in to the live site and click through the same screens again, hoping you remember every step. Drupal has a better way. Its configuration management system lets you build once, export the changes as files, and import them on any other copy of the site.

Content versus configuration

Drupal separates what editors write from how the site is set up. Articles, pages, users and uploaded files are content, and they live only in the database of each site. Content types, fields, Views, image styles, roles and permissions, and most module settings are configuration. Configuration can be exported to YAML files, committed to Git, and deployed like code.

This split matters: you move configuration from local to live, but you never overwrite live content with your local test data.

Set up the sync directory

Drupal needs a folder to read and write configuration files. Keep it outside the web root so it is never served publicly. In settings.php:

$settings['config_sync_directory'] = '../config/sync';

Commit this folder to your Git repository. Every environment (local, staging, live) points to the same path inside its own checkout.

The everyday workflow

With Drush installed through Composer, the cycle is short.

  1. Make the change locally through the admin UI as usual.
  2. Export the active configuration to files:
    drush config:export
  3. Review and commit the changed YAML files. A quick git diff shows exactly what changed, which is a useful review step on its own.
  4. Deploy the code to the server and run:
    drush deploy

drush deploy runs database updates, imports configuration, and rebuilds caches in the correct order. If you prefer to run the steps yourself, use drush updatedb, then drush config:import, then drush cache:rebuild.

Mistakes that cause trouble

  • Editing configuration directly on live. The next import will overwrite it. If someone must change a setting on live, export it there and commit it before the next deployment.
  • Different site UUIDs. Configuration can only be imported into a copy of the same site. Start each new environment from a database copy of the original, not from a fresh install.
  • Forgetting dependencies. If a View uses a module that is not enabled on live, the import fails. Enable modules locally, export, and the core.extension file carries the change for you.
  • Committing secrets. API keys and passwords should not sit in YAML files in Git. Override them in settings.php or environment variables instead.

Settings that differ per environment

Some settings should not match everywhere. You may want the Devel module and verbose error messages only on your laptop, or a different mail setup on staging. Two contributed modules handle this well:

  • Config Split keeps separate sets of configuration that are active only in chosen environments.
  • Config Ignore tells the import to leave certain settings alone, such as a site email address that editors manage on live.

For simple cases, a line in each environment's settings.php is enough, for example $config['system.logging']['error_level'] = 'verbose'; on local only.

Why it is worth the setup

Once configuration lives in Git, every change has a history, a reviewer, and a way back. Deployments stop depending on memory, and a new developer can rebuild the full site setup from the repository in minutes. For agencies and teams running several Drupal sites, it is one of the habits that pays back fastest.

Planning a Drupal build or need help cleaning up an existing site's deployment process? Talk to the Khaga Infotech team.

Category