Skip to main content

How to Set Up Drupal Configuration Split Module for Multi-Site Environments

How to Set Up Drupal Configuration Split Module for Multi-Site Environments
  • Calendar Icon March 6, 2025
  • |
  • Last updated: March 7, 2025
  • Managing configurations across multiple Drupal sites can be challenging. The Configuration Split module allows developers to maintain different configurations for different environments, making multi-site management more efficient and streamlined.

    Why Use Configuration Split in Multi-Site Environments?

    • Environment-Specific Configurations: Define different settings for development, staging, and production environments.
    • Flexible Deployment: Avoid configuration conflicts by separating shared and site-specific settings.
    • Version Control Compatibility: Store only necessary configurations in version control, reducing redundancy.

    Steps to Set Up Configuration Split in Drupal

    1. Install and Enable the Module

    Run the following command to install the module:

    composer require drupal/config_split

    Then, enable it:

    drush en config_split -y

    Alternatively, enable it via the Extend menu in the Drupal admin panel.

    2. Create Configuration Splits

    1. Navigate to Configuration → Development → Configuration Split.
    2. Click Add Split and define a name (e.g., Production Split).
    3. Select the configuration settings that should be included or excluded.
    4. Specify a Folder for Split Configuration (e.g., config/splits/production).
    5. Save the configuration split.

    3. Set Up Environment Detection

    Modify settings.php to activate the correct split based on the environment:

    if (getenv('DRUPAL_ENV') === 'production') {
      $config['config_split.config_split.production']['status'] = TRUE;
    } else {
      $config['config_split.config_split.production']['status'] = FALSE;
    }

    Ensure the DRUPAL_ENV variable is set correctly on your server.

    4. Export and Import Configuration

    Export Configurations

    Run the following command to export configurations, ensuring that splits are properly applied:

    drush csex

    Import Configurations

    When deploying to a specific environment, use:

    drush csim

    This ensures that only the necessary configurations for the current environment are imported.

    Best Practices

    • Use a Consistent Folder Structure: Organize splits into directories like config/splits/dev, config/splits/staging, and config/splits/prod.
    • Avoid Overlapping Settings: Ensure that settings in different splits do not conflict.
    • Automate Deployment: Integrate configuration management into CI/CD pipelines for smooth deployment.

    Conclusion

    The Configuration Split module simplifies configuration management in multi-site Drupal environments by allowing selective overrides per environment. By properly setting up configuration splits, developers can ensure a more controlled, efficient, and error-free deployment process.