unlcms / project-herbie

Drupal 10 implementation at the University of Nebraska–Lincoln
https://cms.unl.edu
GNU General Public License v2.0
5 stars 6 forks source link

Detect environment #30

Closed macburgee1 closed 5 years ago

macburgee1 commented 5 years ago

It will be useful in a number of instances for Drupal to know where it's being run (e.g. production, local development). The primary use case is for the Config Split module.

ericras commented 5 years ago

Could add some sort of of environment variable like $_SERVER['UNLCMSENV']

tsteiner commented 5 years ago

Sure, just add the following to .htaccess: SetEnv UNLCMSENV development

macburgee1 commented 5 years ago

.htaccess is under version control. If we set the environment variable there, it'll follow Drupal through all environments that run in Apache. What are our options for setting the variable in either Apache's global config or in individual VHOSTs?

tsteiner commented 5 years ago

Oh, sorry. I thought there was a separate .htaccess.sample file that was versioned, and a copy of that was used for local config.

macburgee1 commented 5 years ago

I see .htaccess.sample in UNL-CMS-2... hmm. Eric is looking into Aegir. Let's table this for now.

tsteiner commented 5 years ago

I actually just found a good place to put it (just below the RewriteMap rules that have to be in the main config anyway). Its enable on prod and staging now.

macburgee1 commented 5 years ago

@tsteiner - Thanks! Is the variable called 'UNLCMSENV'? What are values for prod and stage?

Below is some example code we'll be using:

<?php
$environment = getenv('UNLCMSENV');

if ($environment == 'production') {
  $config['config_split.config_split.production']['status'] = TRUE;
  $config['config_split.config_split.stage']['status'] = FALSE;
  $config['config_split.config_split.development']['status'] = FALSE;
}
elseif ($environment == 'stage') {
  $config['config_split.config_split.production']['status'] = FALSE;
  $config['config_split.config_split.stage']['status'] = TRUE;
  $config['config_split.config_split.development']['status'] = FALSE;
}
else {
  $config['config_split.config_split.production']['status'] = FALSE;
  $config['config_split.config_split.stage']['status'] = FALSE;
  $config['config_split.config_split.development']['status'] = TRUE;
}
?>
tsteiner commented 5 years ago

Yes, its named "UNLCMSENV", and its value is currently "development" on unlcms-staging.unl.edu, and "production" on unlcms.unl.edu.

macburgee1 commented 5 years ago

Could we change the value on stage to 'stage'?

tsteiner commented 5 years ago

Done!

macburgee1 commented 5 years ago

Thanks! @tsteiner. Closing this issue. Remaining integration with Config Split will happen over on #35.