0

When using Drupal 7 with larger projects, we used a Custom module together with Features, Environment and Environment Indicator modules to keep special environment settings apart. We had at least one feature module for each environment containing something like this:

Production

  • no dblog module active
  • no devel modules
  • all sorts of caching enabled
  • red coloring on Environment Indicator

Staging / Testing

  • dblog module active
  • no devel modules
  • some caching disabled
  • yellow coloring on Environment Indicator

Staging / Testing

  • dblog module active
  • all sorts of devel modules active
  • caching disabled
  • green coloring on Environment Indicator

When developing we used to push new code to production when it was finished and tested. After successful deployment, we cloned the database down to staging and development environments to be sync with the state of production in terms of new content. After that we would run commands like drush env-switch staging to tell Drupal to set environment to Staging and run some custom hooks that would enable the Staging feature module and its settings and dependencies. This way Production, Staging and Develop had different sets of modules and configuration but the same state of content.

After reading and testing into Configuration Management, i fail to see how i could accomplish such a workflow. When using drush config-export staging it exports all current settings into staging directory, which i can check into git and deploy it on my server. Features for D8 lacks of some things that have been in D7. I miss a settings we had in D7 and i am not able to add a dependency without additional settings. I don't depend on Features if there is another way of doing things like this in D8.

What am i missing in D8? What would be the current workflow to get such environment dependent settings and modules active and different environments in Drupal 8?

Thanks for you help!

1

1 Answer 1

1

Drupal 7

Have you considered adding some intelligence to settings.php? You could test $_SERVER['HTTP_HOST'] there, and set $conf['some_variable'] accordingly. Below are some examples from Pantheon. They use their own environment variables to test which environment is running, but you can achieve the same by testing $_SERVER['HTTP_HOST'] or maybe testing file_exists('some_file_which_identifies_environment') - whatever is convenient.

// All Pantheon Environments.
if (defined('PANTHEON_ENVIRONMENT')) {
  // Drupal caching in test and live environments.
  if (in_array(PANTHEON_ENVIRONMENT, array('test', 'live'))) {
    // Anonymous caching - enabled.
    $conf['cache'] = 1;
    // Block caching - enabled.
    $conf['block_cache'] = 1;
    // Expiration of cached pages - 15 minutes.
    $conf['page_cache_maximum_age'] = 900;
    // Aggregate and compress CSS files in Drupal - on.
    $conf['preprocess_css'] = 1;
    // Aggregate JavaScript files in Drupal - on.
    $conf['preprocess_js'] = 1;
  }
  // Drupal caching on dev environment, and all multidevs
  else {
    // Anonymous caching.
    $conf['cache'] = 0;
    // Block caching - disabled.
    $conf['block_cache'] = 0;
    // Expiration of cached pages - none.
    $conf['page_cache_maximum_age'] = 0;
    // Aggregate and compress CSS files in Drupal - off.
    $conf['preprocess_css'] = 0;
    // Aggregate JavaScript files in Drupal - off.
    $conf['preprocess_js'] = 0;
  }

  // Minimum cache lifetime - always none.
  $conf['cache_lifetime'] = 0;
  // Cached page compression - always off.
  $conf['page_compression'] = 0;


  if (PANTHEON_ENVIRONMENT == 'dev') {
    // Google Analytics.
    $conf['googleanalytics_account'] = 'UA-XXXXXXXX-X';
  }
  else if (PANTHEON_ENVIRONMENT == 'test') {
    // Google Analytics.
    $conf['googleanalytics_account'] = 'UA-XXXXXXXX-Y';
  }
  else if (PANTHEON_ENVIRONMENT == 'live') {
    // Google Analytics.
    $conf['googleanalytics_account'] = 'UA-XXXXXXXX-Z';
  }
}

Drupal 8

The same approach can work in Drupal 8, except that the global configuration variable is named $config. This is documented here: Configuration override system and that page shows the example:

$config['system.maintenance']['message'] = 'Sorry, our site is down now.';

5
  • Yes it about D8! It's about adapting my D7 workflow to D8 or get a useful one for D8.
    – rugar
    Aug 27, 2016 at 17:27
  • I've changed the title.
    – rugar
    Aug 27, 2016 at 17:28
  • I've also edited the text to get it my questions more focused to D8. Sorry for not beeing clear enough in the first place.
    – rugar
    Aug 27, 2016 at 17:33
  • Ok, thanks for that. I've updated my answer again. Aug 28, 2016 at 8:01
  • Thanks allot. I've tried that approach and it works pretty well for most cases. It seems i have to wait for a contrib module to come up with some additions to CM.
    – rugar
    Aug 29, 2016 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.