1 description: 'Add support and required config to work with an .env file'
4 This file is a "template" of which env vars need to be defined
5 for your application, use only on development stages.
6 Create real environment variables when deploying to production.
8 If not using real environment variables.
9 Make sure you add the dependency using composer
11 Drupal 8.5 and up versions `composer require symfony/dotenv`
12 if (file_exists(dirname(DRUPAL_ROOT) . '/.env')) {
13 $dotenv = new \Symfony\Component\Dotenv\Dotenv(dirname(DRUPAL_ROOT));
17 Drupal 8.4 and minor versions `composer require vlucas/phpdotenv`
18 if (file_exists(dirname(DRUPAL_ROOT) . '/.env')) {
19 $dotenv = new \Dotenv\Dotenv(dirname(DRUPAL_ROOT));
23 # Load key/value settings
24 $settings_drupal = array_filter(
27 return strpos($key, 'SETTINGS_') === 0;
32 # Set key/value settings
33 foreach ($settings_drupal as $name => $value) {
34 if (substr($name, 0, 9) === 'SETTINGS_') {
35 $key = strtolower(substr($name, 9));
36 $settings['settings'][$key] = $value;