Creating a services.yml File for Drupal 8
Learn how to add a services.yml file for your Drupal 8 site.
Drupal 8 allows users to easily define core services and environment-specific settings within the
sites/default/services.yml configuration file, eliminating the need for hacks to swap functionality. Creating or modifying this file is not required when installing a new Drupal 8 site.
Production and Pre-production Service Configurations
services.yml files may contain environment-specific settings, such as debug-mode settings, or they may be used to configure settings that are applicable to all environments, such as configuring cache contexts, or setting the cookie domain. To avoid the potential for inadvertently deploying debug configuration to production, prior to Drupal 8.2.0, Pantheon placed
sites/default/services.yml in the
.gitignore file, to discourage users from committing this file to the repository.
As of Drupal 8.2.0, however,
services.yml was removed from
.gitignore, and a new mechanism was introduced to control production vs. pre-production configuration changes. Now, in your
sites/default folder, you may use
services.pantheon.preproduction.yml to configure your on-Pantheon service configuration parameters for production and pre-production environments.
The table below illustrates which services file is used in which Pantheon environments:
|Pantheon Environment||Settings Filename|
|Test or Live||services.pantheon.production.yml|
|Dev or any Multidev||services.pantheon.preproduction.yml|
Create and Modify services.yml
Before you begin, make sure that you have updated your Drupal site to version 8.2.0. From within the
sites/default directory, create a new file named
services.pantheon.preproduction.yml, depending on whether you wish to configure settings for all environments, production environments or pre-production environments. Consult the existing
default.services.pantheon.preproduction.yml files for example parameters that you may wish to customize for your site.
Module specific services should be defined in a separate
.yml file, located in the root directory of the respective module (e.g.
View the following Drupal.org resources for more information: