Problem
The new directory layout in D8 hides most parts of the advanced multi-site feature from users that don't need it, which is a good thing:
Top-level
/modules
,/themes
, and/profiles
directories can be used for site-wide extensions.However,
settings.php
must still be placed into/sites/default/settings.php
.This is unnecessary and forces the multi-site concept onto users that shouldn't need to care about it.
In addition, because the multi-site concept is enabled by default, additional calls to
file_exists()
are required on all sites (whethersites.php
exists), even if there is only one site, which harms performance.
Goal
- Simplify the bootstrap by requiring
/settings/settings.php
to exist, and explicitly opt-in for the multi-site functionality.
Proposed solution
Require a top-level, global
/settings/settings.php
to exist in any case (set up by the installer).Merge
/sites/sites.php
into the top-level/settings/settings.php
, and turn the$sites
variable into an explicit flag for enabling the multi-site functionality.This means:
- If the root
/settings/settings.php
does not define the$sites
variable at all, then there is no multi-site functionality and no site directory discovery process. - If the root
/settings/settings.php
defines an empty$sites = array();
, then the multi-site functionality is enabled and the site directory is discovered on every request. - If the root
/settings/settings.php
defines site aliases in the form of$sites['localhost.example'] = 'example.com';
, then the specified site aliases are resolved during the site directory discovery (no change).
This also means:
- When the multi-site functionality is enabled, then the root
/settings/settings.php
acts as if it was a/sites/all/settings.php
, which is a concept that does not exist thus far — i.e., the root/settings.php
can contain shared settings for all sites. - The root
/settings/settings.php
is always loaded first. The site-specificsites/foo/settings.php
has access to all of the global variables and is able to override them in a granular way.
- If the root
→ (Implicitly) Eliminate
/sites/default
. (DX++)If the multi-site functionality is not enabled, the root directory of your Drupal site becomes the site directory itself:
/files /modules /profiles /themes /settings/settings.php
/files
is moved (back) to the document root (as in D6 and below)./sites
no longer exists by default.Note: This patch has to retain
/sites/default/settings.php
due to #2206501: Remove dependency on Drush from test reviewsIntroduce a new
Site
singleton class to replaceconf_path()
.This is required, because if the root directory is the site directory, then a string concatenation like the following would result in an absolute filesystem path:
// If the sire directory path is empty (root directory), then the resulting // filesystem path would become absolute; i.e.: "/some/file" unlink($site_path . '/some/file');
To prevent that, all calls to
conf_path()
are replaced with the following:$site_path_relative = Site::getPath(); $site_path_absolute = Site::getAbsolutePath(); $some_file_relative = Site::getPath('settings.php'); $some_file_absolute = Site::getAbsolutePath('settings.php'); // The argument is a relative subpathname, so this works, too: $some_file_relative = Site::getPath('files/translations/foo/bar.txt');
Move
/sites/default/default.settings.php
into/core/default.settings.php
, so it is updated when Drupal core is updated.
.
.
.
Original summary by @naxoc
This is a split-out from #760992: Where should site specific modules, themes and settings be kept? to move the settings file to the root folder where modules/ themes/ and profiles/ are also going at some point.
It would go for "default" - but not multisite settings files that would still go in the sites folder.
The existence of a sites.php can trigger trying to find multisite settings as suggested in #1055862: Require sites.php to opt-in for multi-site support/functionality