What is the best way to download configuration files for different versions of the same project on the same server?

I have a large php project that relies on two levels of configuration files.

In my project folder, I have a default.config.ini file that loads and then merges with the site-specific configuration file.

Currently, the code is reading an environment variable PROJECT_CONFIGthat points to a specific configuration file. This is great for every developer working on their own machine. The problem arises when we move the project to the server and want to have three instances of the same project: Dev, Stage, Live.

Now we can no longer use the global env var, since it must be different from each subdomain (the project is installed as dev.domain.com, stage.domain.com and www.domain.com).

I looked at converting a server variable HTTP_HOSTto env var and using this to set the correct configuration (that is, when a user requested a page from dev.domain.com, the code would look for env var called dev_domain_com), but I wanted to see what others were doing people and what they recommend.

Any advice would be greatly appreciated, thanks in advance

+3
source share
3 answers

apache SetEnv, PROJECT_CONFIG , :

SetEnv PROJECT_CONFIG /src/dev/app.config.php
+2

- . $_SERVER['HTTP_HOST'], , , . , . :

<?php
  switch($_SERVER['HTTP_HOST']){
    case 'dev.domain.com':
      $path = '/home/dev_user/project.config.ini';
      break;
    case 'stage.domain.com':
      $path = '/home/stage_user/project.config.ini';
      break;
    case 'www.domain.com':
      $path = '/home/live_user/project.config.ini';
      break;
    default:
      $path = '';
  }
  if(!defined('PROJECT_CONFIG')){
    define('PROJECT_CONFIG', $path);
  }
  unset($path);
?>

. $_SERVER['HTTP_HOST'] $_SERVER['SERVER_NAME'].

+2

, . , - . , cms, .

I need to do the same with the presence of dev / stage / production sites that load different configurations and plan to use the environment settings, and detect the host name as a backup if the env parameter is not set.

0
source

Source: https://habr.com/ru/post/1708675/


All Articles