Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Deployment and configuration management are pretty common but very important parts of every project. These processes are too painful in Drupal 7. Drupal 7 stores all configurations in a database together with content. To manage configurations, you probably have worked with a combination of Features, Strongarm, and other related modules. These modules provide a way to package config into the special âfeaturesâ Drupal modules.
Drupal 8 provides a completely different way of managing configurations.The idea is that almost all configurations can be stored in files rather than in a database. It allows developers to move settings between development and live sites easily.
In this article, weâll dive into a new Configuration management system and will learn how to move your configurations from a development environment.As a result, weâll develop a basic workflow which will help to keep your configurations synchronized between environments.
Before we start, we should determine which part of your website can be exported with a help of the new system.
Manage configuration. Not content
Actually, everything besides content is configuration. Following this idea, it is wrong to think that a new configuration management system can help to move content from a development website to a production one. Using the new system you can manage:
- modules settings and states
- content types and settings
- block types and settings
- permissions
- views
- theme settings
- and so on and so forth
The following things are considered as content and canât be managed:
- nodes
- users
- custom block and its content
- other entities content
To move content from dev to prod you probably have to think about a migration system but this is a completely different story.
Letâs examine the configuration management system in action.
Basic settings and preparations
Configuration management functionality is provided by the âConfiguration Managerâ core module. Make sure it is enabled. After that, a new admin page will be available: /admin/config/development/configuration.
This page allows you:
- to import and export configurations (a full archive or a single one);
- to synchronize configuration.
Out of the box active Drupal 8 website configuration is stored in DB in âconfigâ tables. This is done for performance and security reasons.This new system allows us to export complete website configuration and store it in YAMLÂ files.
Before starting working with configuration letâs configure a folder where weâll store our configuration YAML files. This folder is configured in the setting.php file:
$config_directories['sync'] = 'sites/default/files/config_HASH/sync';
HASH here is a long hash generated at the stage of installation; it helps to protect configuration from web access.
Now we can export active website configurations manually or use Drush: drush config-export (or drush cex). We stick to Drupal way and will use Drush in this article.
Letâs stop at this point and think a bit. Almost all website configs are now available as YAML files. What does it mean? YAY! It means that we can store your configuration YAML files under a version control system!
Basic workflow with Git and Drush
We are almost sure that your sites/default/files folder is ignored by the version control system. No? Do it ASAP:)
It is recommended to move your config folder to the same level (a sibling of) as your docroot directory (it fully prevents web access to it). That is not always possible and you can move it to the same level as a public files folder (sites/default/files).
Just move the folder and change the setting.php file:
$config_directories['sync'] = 'sites/default/config_HASH/sync';
After running Drush command, YAML files will be created and you can commit them. Letâs get back to admin UI.
At this stage, there are no configuration changes because we just have exported current active configuration. Letâs change something on a website (e.g. a site name) and see what happens.
We can see that one configuration item (file) was changed. Now we can see the changes:
Whatâs in the picture?
Stage configuration is a configuration which is saved in YAMLÂ files.
Active configuration is a current website configuration stored in a DB.
At this point, it is very important to understand differences between export and import.
Export is for taking all of the configuration defined in the DB and saving it as YAMLÂ files.
Import does the opposite action: it imports the configurations out of YAML files into the DB.
In our example, if you run import using âimport all buttonâ or running drush config-import (drush cim) command, it will wipe out a site name change to a state from YAML files (stage config).
If we want to change our staged config we have to run the export. After that, the appropriate YAML file will be changed and we can commit changes.
To summarize, a basic workflow to move changes from your dev environment to live one is the following:
On a development website:
- Install the configuration management module, configure sync folder, export active configuration and commit it.
- Change configurations.
- Export changes using command: drush cex
- Commit and push changes: git commit and git push
On a live website:
- Pull changed configs: git pull
- Import changes into live website active configuration: drush cim
As a result, our development and live websites get synchronized in a few simple steps.
Conclusion
Drupal 8 strives to make a process of exporting and importing site configuration easier using a new configuration management system. In this article, we have examined a basic workflow which allows to keep your configurations synchronized between development and live environments. I hope that this workflow will help you to improve your deployment process.
Related (helpful) modules / distributions
- Features: allows you to bundle configs to be re-used on another site. Must have a module for Drupal 8 distributions.
- Configuration installer: Drupal profile which allows to install a site from an existing config.
- Configuration Tools: automatically commits config changes to git.
- Configuration Read-only mode: allows to lock any configuration changes via admin UI.
- Configuration development: helps with developing configurations.
- Configuration Synchronizer: provides methods for safely importing site configuration from updated modules, themes, or distributions.
Originally posted at the ADCI Solutions website.
Follow us on social networks: Twitter | Facebook |Â LinkedIn
How to send the JSON data from a Drupal 8 site? - Drupal stories: an insider's view - Medium
Manage your Drupal 8 site configurations was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.