Monday 18 March 2019

Manage Drupal 8 Site Configurations

Manage Site Configurations in Drupal 8

Deployment & Configuration management is very important part of every project. 

In Drupal 7, all configurations are stored in database together with content. To manage configurations, we have to work with combination of feature, Strongarm etc. With the help of these modules, configurations can be packaged into special "features".

In Drupal 8, All the configurations are stored in files as well as in Database. Configuration files allows developer to move settings between development to live site easily.

Manage configurations
Everything excluding content, is configuration. Configuration management system in Drupal 8, only help to move configurations from one dev environment to live environment not content.

Using the new system, manage:
  • Site name
  • Content types and settings
  • Fields
  • Block types and settings
  • Modules settings and states
  • Taxonomy vocabularies
  • Permissions
  • Views
  • theme settings

Following things are content:
  • Nodes
  • Users
  • Taxonomy Terms
  • etc.
To move content from one environment to another, we need migration system.

Configuration Management Settings
Drupal 8 having module "Configuration Manager" in core and its helps in maintaining configuration management functionality. Check that this module is enabled. 

Now go to admin > configuration > development > configuration synchronization.
See in screenshot.
In screenshot, This page having below options:
1. To import and export configurations (a full archive or a single one)
2. To synchronize configuration

Drupal 8, stores configurations in table "config" in Database. This configuration management system allows to export complete configuration and store it in YAML files.

Configure "config" folder to store configuration YAMLs files. This folder can configured in settings.php file:
$config_directories['sync'] = 'sites/default/files/config_HASH/sync';
In above line HASH, 
In above line, 
HASH: It is long hash which is generated at the time of installation. This protect configurations from web access.

In above line, 
HASH: It is long hash which is generated at the time of installation. This protect configurations from web access.

Export Configuration: 
  Export configurations manually or use Drush.
  drush cex (or drush config-export).
  Above command will generate YAML files from configs stored in Database. All the configurations are available after above command.
  Commit all these files to the GIT.
  Now there is no configuration changes after committing all the files. Update site name and now go to configuration synchronize page as shown in screenshot. 

Now check difference between ACTIVE and STAGED files.
STAGED Configuration: It is a configuration available in YAML files.
ACTIVE Configuration: It is a current website configuration stored in Database.
Export: All the configurations which are available in Database, saving them to YAML files.
Import: It is opposite to export. It saves configuration from YAML files to Database.
drush cim:
 This command will update site name in Database from YAML files means staged configuration updated to active configuration.

If i want to update staged configs, i have to run export. Export will update YAML files as per Database changes available. Now commit these files.
Steps:
1. Install "configuration manager" module and configure "sync" folfer.
2. Export active configurations and commit all those configuration YAML files from sync directory.
3. Change configuration.
4. drush cex
5. git commit and git push

Non on Live Environment:
1. git pull : pull changed configs
2. drush cim : Import changes into live environment active configuration.
Now development and live environment are both in sync with help of above steps.

No comments:

Post a Comment