{"id":64713,"date":"2024-09-07T12:21:06","date_gmt":"2024-09-07T06:51:06","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=64713"},"modified":"2024-09-09T10:43:25","modified_gmt":"2024-09-09T05:13:25","slug":"mastering-configuration-synchronization-in-drupal-10","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/mastering-configuration-synchronization-in-drupal-10\/","title":{"rendered":"Mastering Configuration Synchronization in Drupal 10"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p>Drupal&#8217;s Configuration Management system, introduced in Drupal 8 and refined in Drupal 10, allows developers to manage site configurations in a standardized and predictable manner. Whether you are working in a team or managing multiple environments (like development, staging, and production), Configuration Synchronization ensures consistency and reliability across all setups. This blog will guide you through the entire process of Configuration Synchronization in Drupal 10, covering necessary modules, commands, and best practices.<\/p>\n<h2><strong><br \/>\nWhat is Drupal Configuration Synchronization?<\/strong><\/h2>\n<p>Drupal Configuration Synchronization is the process of managing and synchronizing site configuration between different environments (e.g., development, staging, production). Configuration in Drupal refers to settings that determine how a site behaves, including content types, views, fields, and user permissions. Unlike content, which changes frequently and is stored in the database, configuration is more stable and is typically managed as code.<\/p>\n<p>Configuration synchronization ensures that the settings and configuration across multiple environments are consistent, allowing for predictable behavior and reducing the chances of configuration drift, where different environments might have different settings due to manual changes or oversight.<\/p>\n<h2><strong><br \/>\nWhy Do We Need Configuration Synchronization?<\/strong><\/h2>\n<p>Configuration synchronization is essential for several reasons:<\/p>\n<ul>\n<li>Consistency Across Environments: It ensures that all environments (development, staging, production) are identical in terms of configuration, which is crucial for testing and deploying updates.<\/li>\n<li>Version Control: By exporting configuration into code, it can be versioned using Git or another version control system, allowing teams to track changes, roll back to previous versions, and collaborate more effectively.<\/li>\n<li>Disaster Recovery: In case of accidental deletion or misconfiguration, you can quickly restore the site to a previous state using the configuration stored in the code.<\/li>\n<li>Deployment: When deploying changes from a development environment to production, configuration synchronization makes it easy to apply these changes without manual intervention, reducing the risk of errors.<\/li>\n<li>Rapid Development: Configuration synchronization allows for the reuse of configurations across different environment and reduce development cost.<\/li>\n<\/ul>\n<h2><strong><br \/>\nUnderstanding Drupal Configuration<\/strong><\/h2>\n<p>In Drupal 10, configuration data is stored in YAML files. These files contain settings for content types, views, taxonomy vocabularies, and more. The configuration is stored in the config directory within the site\u2019s files directory, typically located at sites\/default\/files\/config_HASH\/sync, where HASH is a unique identifier generated by Drupal.<\/p>\n<p>When you export your site\u2019s configuration, Drupal writes these settings into YAML files that can be stored in a version control system. Conversely, importing configuration reads these files and applies the settings to the site.<\/p>\n<h2><strong><br \/>\nWhat Data Will Be Considered as Configuration?<\/strong><\/h2>\n<p>In Drupal, the <strong>State API<\/strong> is used to store temporary or internal site information that isn\u2019t part of the site\u2019s main configuration. This data is not meant to be synchronized across different environments like development or production. Instead, it&#8217;s used for things that are specific to a particular environment or session.<\/p>\n<h3><strong>State Data vs. Configuration Data:<\/strong><\/h3>\n<ul>\n<li><strong>Configuration Data:<\/strong> These are settings that define how your site works, like content types, views, and user permissions. This data is stored in YAML files and synchronized across all your environments.<\/li>\n<li><strong>State Data:<\/strong> This is more like temporary or environment-specific information. It\u2019s saved in the database and is not synchronized across environments.<\/li>\n<\/ul>\n<h3><strong>Examples of Configuration Data:<\/strong><\/h3>\n<ul>\n<li><strong>Content Types:<\/strong> Definitions of different content types like Articles or Events.<\/li>\n<li><strong>Views:<\/strong> Configurations for custom views, such as lists of content or user profiles.<\/li>\n<li><strong>Taxonomy Vocabularies:<\/strong> Definitions of terms and categories used for tagging content.<\/li>\n<li><strong>User Roles and Permissions:<\/strong> Settings that control user access and permissions on the site.<\/li>\n<li><strong>Menu Structures:<\/strong> Configuration for the main navigation menu and submenus.<\/li>\n<\/ul>\n<h3><strong>Examples of State Data:<\/strong><\/h3>\n<ul>\n<li><strong>Last Cron Run Time:<\/strong> Records when the last automated task (cron job) was performed.<\/li>\n<li><strong>Module Settings:<\/strong> Temporary settings used by modules, such as feature toggles or user preferences.<\/li>\n<li><strong>User Login Status:<\/strong> Information related to active user sessions or login statuses.<\/li>\n<li><strong>Cache Data:<\/strong> Data stored temporarily to improve site performance, like cached views or pages.<\/li>\n<li><strong>Temporary File Paths:<\/strong> Paths for files used temporarily during operations, like import\/export tasks.<\/li>\n<\/ul>\n<h2><strong><br \/>\nConfiguration Management System in Drupal<\/strong><\/h2>\n<p>Drupal\u2019s Configuration Management System (CMS) revolves around the concept of the active configuration and the staged configuration.<br \/>\n<strong>Active Configuration:<\/strong> This is the configuration that the site is currently using. It is stored in the database and is automatically updated when you make changes through the Drupal UI.<\/p>\n<p><strong>Staged Configuration:<\/strong> This refers to a configuration that has been exported to YAML files and is ready to be imported back into the site. The staged configuration is typically stored in the sync directory.<\/p>\n<p>The Config file locations are mapped in the\u00a0settings.php\u00a0file, It is recommended to have the configuration files out of the root directory.<\/p>\n<pre>$settings['config_sync_directory'] = '..\/config\/sync';<\/pre>\n<h2><strong><br \/>\nConfiguration Workflow<\/strong><\/h2>\n<p>The typical workflow for managing configuration in Drupal involves three main steps: exporting, versioning, and importing.<br \/>\n<strong>Export Configuration:<\/strong> Export the current site configuration to YAML files.<br \/>\n<strong>Version Configuration:<\/strong> Add the exported files to version control (e.g., Git) and push changes to a remote repository.<br \/>\n<strong>Import Configuration:<\/strong> Import the configuration on another environment (e.g., staging or production) to apply the changes.<\/p>\n<h2><strong><br \/>\nConfiguration Export<\/strong><\/h2>\n<p>Exporting configuration is the first step in the configuration management workflow. This process writes the active configuration to YAML files in the sync directory.<\/p>\n<p><strong>Exporting Configuration<\/strong><\/p>\n<ol>\n<li>Navigate to the site\u2019s admin interface: <strong>Configuration<\/strong> &gt; <strong>Development<\/strong> &gt; <strong>Configuration synchronization.<\/strong><\/li>\n<li>Click on the <strong>Export<\/strong> tab.<\/li>\n<li>You can export the entire configuration or specific parts of it.<\/li>\n<li>Click Export to download the tar.gz file containing all the YAML configuration files.<\/li>\n<\/ol>\n<div id=\"attachment_64698\" style=\"width: 686px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-64698\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-64698\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/08\/synchronization-page.png\" alt=\"synchronization\" width=\"676\" height=\"332\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/08\/synchronization-page.png 932w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/synchronization-page-300x147.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/synchronization-page-768x377.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/synchronization-page-624x307.png 624w\" sizes=\"(max-width: 676px) 100vw, 676px\" \/><p id=\"caption-attachment-64698\" class=\"wp-caption-text\">drupal config export<\/p><\/div>\n<pre>Alternatively, you can use Drush, a command-line shell and scripting interface for Drupal, to export configuration:\r\n\r\ndrush config-export OR drush cex\r\n\r\n<\/pre>\n<div id=\"attachment_64700\" style=\"width: 635px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-64700\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-64700 size-large\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/08\/drush-cex-1024x544.png\" alt=\"drush-cex\" width=\"625\" height=\"332\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/08\/drush-cex-1024x544.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/drush-cex-300x159.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/drush-cex-768x408.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/drush-cex-624x332.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/drush-cex.png 1142w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><p id=\"caption-attachment-64700\" class=\"wp-caption-text\">config export<\/p><\/div>\n<p>This command exports the entire configuration to the sync directory.<\/p>\n<h2><strong><br \/>\nConfiguration Import<\/strong><\/h2>\n<p>After exporting and versioning the configuration, you\u2019ll want to import it into another environment. This process reads the YAML files from the sync directory and updates the active configuration in the database.<\/p>\n<p><strong>Importing Configuration<\/strong><\/p>\n<ol>\n<li>Navigate to the site\u2019s admin interface: <strong>Configuration<\/strong> &gt; <strong>Development<\/strong> &gt; <strong>Configuration synchronization.<\/strong><\/li>\n<li>Click on the <strong>Import<\/strong> tab.<\/li>\n<li>You can choose to import the entire configuration or specific parts.<\/li>\n<li>If you are importing a complete set of configurations, make sure you have the relevant YAML files prepared.<\/li>\n<li>Upload the tar.gz file containing the YAML configuration files. This file is usually the result of a configuration export from another environment.<\/li>\n<\/ol>\n<div id=\"attachment_64895\" style=\"width: 686px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-64895\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-64895\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/08\/Screenshot-from-2024-08-30-15-01-01-1024x430.png\" alt=\"config import\" width=\"676\" height=\"284\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/08\/Screenshot-from-2024-08-30-15-01-01-1024x430.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/Screenshot-from-2024-08-30-15-01-01-300x126.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/Screenshot-from-2024-08-30-15-01-01-768x323.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/Screenshot-from-2024-08-30-15-01-01-624x262.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/08\/Screenshot-from-2024-08-30-15-01-01.png 1395w\" sizes=\"(max-width: 676px) 100vw, 676px\" \/><p id=\"caption-attachment-64895\" class=\"wp-caption-text\">drupal config import<\/p><\/div>\n<pre>Alternatively, you can use Drush, a command-line shell and scripting interface for Drupal, to import configuration:\r\n\r\ndrush config-import OR drush cim\r\n\r\n<\/pre>\n<p>This command imports the configuration from the sync directory and applies it to the active configuration.<\/p>\n<h2><strong><br \/>\nConfig Split<\/strong><\/h2>\n<p>Config Split is a contributed module in Drupal that allows for the management of different configurations in different environments. It is particularly useful for handling configurations that should vary between environments (e.g., development, staging, and production).<\/p>\n<pre>you can install config split module using command line -\r\n\r\ncomposer require drupal\/config_split\r\n\r\ndrush en config_split\r\n\r\n<\/pre>\n<p><strong>Use Case Example:<\/strong><\/p>\n<p>Let Suppose we have a Drupal site that requires different email settings in development and production environments. The goal is to ensure that email functionalities are configured appropriately for testing and live use.<\/p>\n<p>Using Config Split, you can create different configuration splits for your environments:<\/p>\n<p><strong>Development Split:<\/strong> Create a configuration split for development with settings for a test email address.<br \/>\n<strong>Production Split:<\/strong> Create a configuration split for production with settings for real email addresses.<\/p>\n<p><strong>How It Works:<\/strong><\/p>\n<ul>\n<li>You define multiple configuration splits in the Config Split settings.<\/li>\n<li>Each split specifies which configuration settings should be included or excluded.<\/li>\n<li>During the export and import process, Drupal uses these splits to manage environment-specific configurations seamlessly.<\/li>\n<\/ul>\n<h2><strong><br \/>\nHow to Segregate Configuration Between Non-Prod and Prod Environments?<\/strong><\/h2>\n<p>To effectively manage and segregate configuration between non-production (e.g., local, dev, qa, prod) and production environments, follow these practices:<br \/>\n1. Navigate to the site\u2019s admin interface: <strong>Configuration<\/strong> &gt; <strong>Development<\/strong> &gt; <strong>Configuration Split Settings<\/strong>.<br \/>\n2. Click <strong>Add Configuration Split Settings<\/strong>.<br \/>\n3. Enter the label and the folder name, Select the modules you want to split and click save.<\/p>\n<div id=\"attachment_65099\" style=\"width: 573px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65099\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-65099 size-large\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Add-configuration-split-setting-Druapl-10-2-563x1024.png\" alt=\"Config Split\" width=\"563\" height=\"1024\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Add-configuration-split-setting-Druapl-10-2-563x1024.png 563w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Add-configuration-split-setting-Druapl-10-2-165x300.png 165w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Add-configuration-split-setting-Druapl-10-2-768x1397.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Add-configuration-split-setting-Druapl-10-2-844x1536.png 844w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Add-configuration-split-setting-Druapl-10-2-1126x2048.png 1126w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Add-configuration-split-setting-Druapl-10-2-624x1135.png 624w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Add-configuration-split-setting-Druapl-10-2.png 1858w\" sizes=\"(max-width: 563px) 100vw, 563px\" \/><p id=\"caption-attachment-65099\" class=\"wp-caption-text\">Drupal Config Split<\/p><\/div>\n<p><strong>Use Different Configuration Directories:<\/strong><br \/>\nConfigure Drupal to use different sync directories for different environments. For example, in your settings.php file, you can specify different directories for non-production and production environments:<\/p>\n<pre>\/\/ Configure the Config Split module for different environments\r\n$config['config_split.config_split.local_split']['status'] = FALSE;\r\n$config['config_split.config_split.dev_split']['status'] = TRUE;\r\n$config['config_split.config_split.qa_split']['status'] = FALSE;\r\n$config['config_split.config_split.prod_split']['status'] = FALSE;\r\n\r\n<\/pre>\n<p><strong>Note:<\/strong> You should adjust the true\/false status of the configuration splits based on your current environment. For example, if you are in the dev environment, you would enable dev_split and disable others.<br \/>\nMake sure your directory structure for the configuration is correctly set up to match the config_sync_directory path specified in the settings.php file:<\/p>\n<h2><strong><br \/>\nConclusion<\/strong><\/h2>\n<p>Drupal 10&#8217;s Configuration Synchronization system is a powerful tool that ensures consistency across different environments, simplifies deployment, and enhances collaboration through version control. By understanding and properly utilizing the export and import processes, you can maintain a stable and predictable Drupal site across development, staging, and production environments.With this approach, you&#8217;ll have a robust workflow that minimizes the risk of configuration drift and keeps your Drupal site\u2019s configuration under control.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Drupal&#8217;s Configuration Management system, introduced in Drupal 8 and refined in Drupal 10, allows developers to manage site configurations in a standardized and predictable manner. Whether you are working in a team or managing multiple environments (like development, staging, and production), Configuration Synchronization ensures consistency and reliability across all setups. This blog will guide [&hellip;]<\/p>\n","protected":false},"author":1708,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":284},"categories":[3602],"tags":[3709,4862,5859,5096],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/64713"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1708"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=64713"}],"version-history":[{"count":13,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/64713\/revisions"}],"predecessor-version":[{"id":65482,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/64713\/revisions\/65482"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=64713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=64713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=64713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}