Page MenuHomePhabricator

Get MW_CONFIG_FILE from env to facilitate virtual hosting
Open, LowPublic

Description

includes/WebStart.php allows for the possibility that MW_CONFIG_FILE has already been defined externally, but there is no mechanism in the code to facilitate it being predefined. My suggestion/request is to check the environment, see if a variable with such name is defined there, and if so pull its value in just as is already done with IP earlier in the same file.

The advantage of this feature would be that a virtual hosting web server could use the same MW code base to serve multiple different wikis simply by configuring this env var to point to the appropriate LocalSettings.php for each one.

Current workaround: In Apache, for each wiki I set:

SetEnv MW_CONFIG_FILE Path_to_this_wikis_LocalSettings.php
php_admin_value auto_prepend_file getMW_CONFIG_FILE_from_Env.php

Where getMW_CONFIG_FILE_from_Env.php contains just the one line:

define('MW_CONFIG_FILE', getenv( 'MW_CONFIG_FILE' ));

The present request would make only the one SetEnv customization line necessary for each host. I consider this to be a cleaner solution, at least for some situations, than other current options such as https://www.mediawiki.org/wiki/Manual:Wiki_family#Giant_switch_statement.

Event Timeline

Zacharyharris raised the priority of this task from to Low.
Zacharyharris updated the task description. (Show Details)
Zacharyharris subscribed.

Change 582499 had a related patch set uploaded (by Kosta Harlan; owner: Kosta Harlan):
[mediawiki/core@master] Allow setting MW_CONFIG_FILE via environment variable

https://gerrit.wikimedia.org/r/582499

Change 582499 abandoned by Kosta Harlan:
Allow setting MW_CONFIG_FILE via environment variable

Reason:
per comments

https://gerrit.wikimedia.org/r/582499

Per T182020, the way this can now be done is by creating includes/PlatformSettings.php from which you include or set the settings for a given virtually hosted wiki. This can be directly integrated with information the service provider has, including based on an environment variable if preferred. In that case the hoster would create something like the below in the central install:

includes/PlatformSettings.php
require_once getenv( 'MW_CONFIG_FILE' );

The PlatformSettings.php file is automatically picked up by the installer when creating the first wiki, but for an existing wiki farm you'd add the following to the top of your LocalSettings.php file:

require_once "$IP/includes/PlatformSettings.php";

Of course, if you already have this set up, you can also place this directly in the central LocalSettings.php file.