Drupal · 13 min read · Updated

Drupal Configuration Management and Acquia Cloud Hooks: Config Split, drush deploy and Automatic Database Scrubbing

Drupal configuration management rules that stop surprise imports, and the Cloud Hooks and Cloud Actions that automate what people forget after deployments and database copies.

Drupal configuration management Acquia cloud hooks

This is Part 4 of 10 in Drupal on Acquia: Enterprise Operations Guide, a free series for the people who run Drupal sites on Acquia Cloud Platform. Drupal configuration management rules that stop surprise imports, and the Cloud Hooks and Cloud Actions that automate what people forget after deployments and database copies.

Drupal configuration management on Acquia

The release that broke the corporate site’s main menu contained no code changes at all. It was a configuration export. A developer had changed a block setting on Dev, exported all configuration, and committed it. The export also contained a dozen unrelated changes that had drifted on Dev over the previous month, including a menu configuration from an abandoned experiment. When the release was deployed and drush cim imported the configuration, production’s main menu was replaced with the experimental one.

Configuration management is one of Drupal’s most powerful features and one of the most common sources of deployment failures. This section explains how to manage it safely on Acquia.

Configuration flows from local to Git to every environment; content is created on production (diagram from the Drupal on Acquia: Enterprise Operations Guide series)
Configuration flows from local to Git to every environment; content is created on production.

Content versus configuration

Drupal separates two kinds of data:

  • Content is what editors create: pages, articles, media, users, menu links created by editors, taxonomy terms in many cases. Content lives in the database and is created directly on production.
  • Configuration is how the site is built: content types, fields, views, block placements, image styles, roles and permissions, module settings. Configuration should be created in development, exported to files, committed to Git and deployed like code.

The configuration management system lets you export configuration to YAML files (drush cex) and import it into another environment (drush cim). On deployment, importing configuration makes the target environment’s configuration match the files in Git.

The key mental model: for configuration, Git is the source of truth. For content, production is the source of truth.

Where configuration lives

Configuration files are stored in a sync directory, set in settings.php. On Acquia, the convention is a config directory next to docroot, outside the web root, for example config/default. Keeping it outside docroot means configuration files are never served to the web.

The golden rules

  1. Never change configuration directly on production. If production configuration is changed through the admin interface, the next deployment’s import will overwrite it. Make configuration changes in development, export them and deploy them.
  2. Export only what you mean to change. Before committing, review the configuration diff line by line. Unexpected changes are a warning sign.
  3. Start from current configuration. Before making changes, pull the latest code and run drush cim locally so your environment matches Git. Then make your change and export.
  4. Import on every deployment. Run configuration import automatically after every deployment, through drush deploy (see the Cloud Hooks section). A deployment that skips import leaves production out of step with Git.
  5. Treat configuration conflicts like code conflicts. Resolve them carefully. Merging YAML files by guesswork causes subtle breakage.

Environment-specific configuration

Some configuration must differ between environments. Common examples:

  • Development modules (such as Devel or Stage File Proxy) enabled only on Dev and local.
  • Performance settings, such as CSS and JavaScript aggregation, turned off locally.
  • Search connection settings pointing to different indexes per environment.
  • Email settings that stop non-production environments from emailing real users.
  • API endpoints for integrations that have test and production versions.

There are three main tools for this.

settings.php overrides

Simple values can be overridden in settings.php, using the AH_SITE_ENVIRONMENT variable to apply different values per environment. Overrides set this way are not exported with configuration, which keeps environment-specific values out of the sync directory.

if (isset($_ENV['AH_SITE_ENVIRONMENT'])
  && $_ENV['AH_SITE_ENVIRONMENT'] !== 'prod') {
  // Never send real email from non-production environments.
  $config['system.mail']['interface']['default'] = 'test_mail_collector';
}

Config Split

The Config Split module lets you define sets of configuration that apply only in certain environments. For example, a “dev” split can enable development modules and their settings, active only when the environment is Dev or local. Splits are activated in settings.php based on the environment. This is the standard approach for enabling or disabling modules per environment.

Config Ignore

The Config Ignore module tells Drupal to skip certain configuration during import, so it can be changed on production without being overwritten. Use it sparingly, for settings that business users legitimately manage on production, such as a site-wide announcement or certain webform settings. Every ignored item is configuration that Git no longer controls.

Configuration that editors change

Some sites let editors or site builders change configuration on production, for example by editing views or block layouts. This conflicts with the golden rules, because the next import overwrites their changes.

Choose one of these approaches deliberately:

  • Lock it down. Remove configuration permissions from production roles, so all configuration changes go through development.
  • Ignore it. Add the specific configuration to Config Ignore, accepting that Git no longer controls it.
  • Export it back. If production changes are allowed, export them regularly into Git before each release, review them and commit them. This is fragile and should be a last resort.

Many configuration problems disappear once you make this decision explicitly.

Checking configuration before deployment

Add checks so configuration problems are caught before production:

  • In CI: install the site from configuration, or import configuration into a copy of the production database, and fail the pipeline if the import has errors.
  • On Stage: after deploying, run drush config:status to confirm that active configuration matches the files. It should report no differences.
  • On production, before deploying: run drush config:status to see whether anyone has changed configuration directly. If differences appear, find out why before the import overwrites them.

Environment indicator

A small but valuable addition: the Environment Indicator module, or a similar approach, shows a colored bar in the admin interface telling users which environment they are on. It prevents the common mistake of making changes on production while believing you are on Stage. Configure it per environment in settings.php.

Webocreation Group: No more surprise imports

After the menu incident, Arjun introduced four changes. Every configuration commit now required a reviewed diff in the merge request. The pipeline imported configuration into a fresh copy of the scrubbed production database and failed on errors. Before every production deployment, the platform lead ran drush config:status on production and investigated any differences. And editors’ production roles lost permission to change views and blocks, with two settings, the site-wide alert banner and a webform’s recipient list, moved into Config Ignore.

In the following six months, no deployment caused a configuration surprise. The config status check on production caught two cases where someone had changed settings directly, both of which were exported into Git properly before the next release.

Template: Configuration management policy

TopicOur rule
Sync directoryconfig/default, outside docroot
Where configuration changes are madeLocal or Dev only; exported and committed
Production configuration changesNot allowed, except items listed in Config Ignore
Config Ignore itemsAlert banner settings; contact webform recipients
Environment-specific configurationConfig Split for modules; settings.php overrides for values
ReviewEvery configuration diff reviewed in the merge request
CI checkConfiguration import into scrubbed production copy must succeed
Pre-deployment checkdrush config:status on Prod; investigate any difference
Post-deployment checkdrush config:status on Prod shows no differences
Environment indicatorRed for Prod, orange for Stage, green for Dev

Checklist

  • Confirm the config sync directory sits outside docroot and is committed to Git.
  • Run configuration import automatically on every deployment.
  • Set up Config Split for environment-specific modules and settings.
  • Decide how production configuration changes are handled, and restrict permissions accordingly.
  • Review every configuration diff before merging.
  • Add a configuration import check to CI.
  • Check drush config:status on production before and after deployments.
  • Add an environment indicator to every environment.

Common traps

  • Exporting everything without looking. Drift from Dev leaks into production.
  • Changing configuration on production. The next import silently overwrites it.
  • Overusing Config Ignore. Every ignored item escapes version control.
  • Skipping import after deployment. Production quietly falls out of step with Git.
  • Real emails from Stage. Override mail settings on every non-production environment.

Cloud Hooks and Cloud Actions

Three weeks after taking over, Arjun copied the production database to Stage so the marketing team could test a new campaign. The next morning, eleven real customers received password reset emails from the Stage site. A tester had clicked a link that triggered a bulk action, and Stage, running with a full copy of real user data and live email settings, did exactly what production would have done.

The fix was not more care from testers. It was automation: every database copied to a non-production environment should be scrubbed automatically, every time, with no human step to forget. On Acquia, that automation is done with Cloud Hooks and, on Cloud Next, Cloud Actions.

Which hook runs on which platform event, and the scripts Webocreation Group attached to each (diagram from the Drupal on Acquia: Enterprise Operations Guide series)
Which hook runs on which platform event, and the scripts Webocreation Group attached to each.

What Cloud Hooks are

Cloud Hooks are scripts in your repository that Cloud Platform runs automatically when certain events happen. They live in the hooks directory at the root of your repository, next to docroot. Within it, scripts are organized by environment and event:

hooks/
  common/                 Runs on all environments
    post-code-deploy/
    post-code-update/
    post-db-copy/
    post-files-copy/
  dev/                    Runs only on Dev
  test/                   Runs only on Stage
  prod/                   Runs only on Prod
  templates/              Example scripts, not executed

The standard events are:

EventWhen it runsTypical use
post-code-deployAfter code is deployed to an environment through the interface or APIRun drush deploy; clear caches; notify a channel
post-code-updateAfter new commits are pushed to a branch an environment tracksSame as post-code-deploy, for Dev
post-db-copyAfter a database is copied into an environmentScrub personal data; adjust settings for the environment
post-files-copyAfter files are copied into an environmentAdjust file permissions; remove sensitive files

Cloud Platform passes arguments to each script, such as the site name, the target environment and, for some events, the source environment and the deployed branch or tag. Acquia publishes sample hook scripts in a public repository, which you can copy into your hooks directory as a starting point. Check the current samples and documentation for the exact arguments.

A post-deployment hook

The most important hook runs Drupal’s post-deployment tasks after every deployment. A simple version looks like this:

#!/bin/sh
# hooks/common/post-code-deploy/01-drush-deploy.sh
site="$1"
target_env="$2"
drush @$site.$target_env deploy -y

Place the same script, or a link to it, in post-code-update so pushes to Dev also run it. The script must be executable (chmod +x) and committed to Git.

drush deploy runs database updates, imports configuration, rebuilds caches and runs any deploy hooks in your custom modules. If it fails, the hook fails, and the Cloud Platform task log shows the error. Always check the task log after a deployment.

A database scrub hook

The second essential hook scrubs data after a database copy to any non-production environment:

#!/bin/sh
# hooks/common/post-db-copy/01-scrub.sh
site="$1"
target_env="$2"
if [ "$target_env" = "prod" ]; then
  echo "Not scrubbing production."
  exit 0
fi
drush @$site.$target_env sql:sanitize -y
drush @$site.$target_env cr

drush sql:sanitize replaces user email addresses and passwords with safe values by default. Many sites need more: webform submissions, customer records in custom tables, order data, API tokens stored in the database. Extend the scrub with your own SQL or Drush commands, and test it by checking a scrubbed database for any remaining personal data.

The production check at the top is a safety net. Production should never receive a database copy in normal operations, but if it ever does during a planned migration, the scrub must not run.

Cloud Actions on Cloud Next

On Cloud Next environments, Cloud Platform also offers Cloud Actions: built-in automation for common deployment tasks, configured in the Cloud Platform interface rather than written as scripts. You can set default actions for each environment, such as running database updates, importing configuration and clearing caches after a deployment, and override them per environment.

Cloud Actions and Cloud Hooks can work together, but avoid running the same task twice. If Cloud Actions runs database updates and configuration import, your post-code-deploy hook should not run drush deploy as well. Decide which mechanism owns which task, document it, and check the task log to confirm what actually runs.

A practical split for many teams:

  • Cloud Actions for the standard Drupal deployment steps, where they are available.
  • Cloud Hooks for custom tasks: database scrubbing, notifications, warming caches, and anything specific to your site.

Rules for safe hooks

  • Keep hooks short and focused. One task per script, numbered for order (01-, 02-).
  • Fail loudly. Scripts should exit with an error code when something goes wrong, so the task log shows a failure instead of a false success.
  • Never put secrets in hooks. Cloud Hooks are stored in your repository and are not encrypted. Acquia’s documentation explicitly warns against including credentials, keys or certificates. Read secrets from environment variables or a secrets service instead.
  • Watch the time. Hooks have time limits. On Cloud Next, hooks time out after three hours. Long-running work, such as reindexing a large search index, belongs in a queue or a scheduled job, not a deployment hook.
  • Test hooks on Dev first. A broken post-code-deploy hook can leave every deployment half-finished.
  • Log what happens. Echo clear messages so the task log tells a readable story.

Notifications

A small hook can post a message to your team chat after each deployment, with the environment, the tag or branch, and whether drush deploy succeeded. Store the webhook URL in an environment variable, not in the script. Notifications make deployments visible to everyone and help spot failed deployments quickly.

Webocreation Group: Scrubbed by default

Arjun replaced the contractor’s single, untested hook with four scripts: drush deploy after code deployments on all environments, a scrub after database copies to any environment other than production, a cache warm-up for the top 50 pages on Prod, and a chat notification. The scrub covered user accounts, webform submissions and a custom table of lead records synced from the CRM. He tested it by searching a scrubbed copy for real email domains and found none.

Since then, every database copied to Stage or Dev has been scrubbed automatically. Testers stopped worrying about real customers, and the privacy team signed off on using production copies for testing.

Template: Cloud Hooks inventory

ScriptEventEnvironmentsWhat it doesOwnerLast tested
01-drush-deploy.shpost-code-deploy, post-code-updateAllRuns drush deployPlatform teamThis month
01-scrub.shpost-db-copyDev, Stage, others (never Prod)Sanitizes users, webform submissions, lead recordsPlatform teamThis month
02-warm-cache.shpost-code-deployProdRequests top 50 URLs to warm Varnish and CDNPlatform teamThis quarter
99-notify.shpost-code-deployAllPosts deployment result to team chatPlatform teamThis quarter

Checklist

  • Add a post-deployment hook or Cloud Action that runs database updates, configuration import and cache rebuild.
  • Add a post-db-copy scrub hook for every non-production environment.
  • Extend the scrub to cover all personal data in your database, and test it.
  • Decide which tasks Cloud Actions owns and which Cloud Hooks owns.
  • Remove any secrets from hook scripts.
  • Add deployment notifications to team chat.
  • Check the task log after every deployment.

Common traps

  • Manual scrubbing. Someone will forget. Automate it.
  • Secrets in hooks. Hooks are stored in Git and are not encrypted.
  • Silent failures. Hooks that do not exit with errors report success when they fail.
  • Running tasks twice. Cloud Actions and Cloud Hooks doing the same work can cause conflicts.
  • Long-running hooks. Heavy work belongs in queues or scheduled jobs.
Drupal on Acquia: Enterprise Operations Guide (full PDF)Every article from this series in one printable PDF.PDF · 560.0 KB
Free download: unlock it in one step

Share this page

or

Mailchimp opens in a new tab to confirm. Unsubscribe any time.

Filed underDrupal
Rupak Nepali
Written byRupak Nepali

Rupak Nepali is a web developer, manage Webocreation website and the author of six books:
Getting Started with OpenCart Module Development (Packt, 2013),
OpenCart Theme and Module Development (Packt, 2015),
OpenCart 4: Dev Guide for Themes & Extensions (2024),
OpenCart 4: User Manual (2025),
Cloudflare for the Enterprise Website (2026) and
The Technical Web Guide for Marketers (2026).
Rupak has built OpenCart stores and extensions since 2010, has published more than 600 tutorials on Webocreation, and shares free OpenCart extensions on GitHub.
Find Rupak on
GitHub | Amazon | LinkedIn | X | YouTube.

Leave a Reply

Your email address will not be published. Required fields are marked *