For the Drupal 7 part of this issue see #1055856: Optimize settings.php discovery. Even if that gets bumped to D8 this part should be a separate issue.
For Drupal 8, we could look at making sites.php required, then with sites.php set up to map correctly, a strace looks like:
9072 stat("/home/catch/www/7/sites/sites.php", {st_mode=S_IFREG|0644, st_size=1782, ...}) = 0
9072 stat("/home/catch/www/7/sites/default/settings.php", {st_mode=S_IFREG|0555, st_size=15272, ...}) = 0
In the installer, we could consider actually writing to sites.php automatically based on request path and the location of settings.php (possibly even accounting for multisite installs correctly by reading the existing array in and writing it back out again with the new site added. This would allow us to skip searching for the settings.php in the majority of cases, without manually having to set it up.
If that's not doable, we could also probably add a (commented out) catch all to sites.php that takes the request path, and maps this to default dynamically. Non-multisites could then uncomment this and get a decent saving. You'd have to comment it again if you converted from single site to multisite. This is a bit nasty but putting it here anyway.
Here's a patch that just requires sites.php, it includes the changes from the D7 issue for now.
Comment | File | Size | Author |
---|---|---|---|
#28 | drupal8.sites_.28.patch | 1.81 KB | sun |
#27 | drupal8.sites_.27.patch | 992 bytes | sun |
#20 | drupal8.sites_.20.patch | 1.19 KB | sun |
#10 | drupal8.sites_.10.patch | 2.39 KB | sun |
#9 | drupal8.sites_.9.patch | 2.38 KB | sun |
Comments
Comment #1
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #2
pillarsdotnet CreditAttribution: pillarsdotnet commentedRe-rolled with
git format-patch
Comment #3
tstoecklerThere is another file_exists which can be removed:
Comment #4
catchActually the change in #3 is the only one we want here, the rest is handled by #1055856: Optimize settings.php discovery.
Leaving at needs work since there needs to be an installer requirement to copy this file over.
Comment #5
catchAlthough uploading the patch would've been good.
Comment #7
sunComment #8
quicksketchI'm interested in this issue as a continuation of #22336: Move all core Drupal files under a /core folder to improve usability and upgrades. Though it's out of scope for this issue, it would be good to take into consideration further possible restructuring, such as removing the "sites/default" directory entirely or making it optional by putting files and settings.php in the root. The fewer directories we make our users navigate the better in my opinion.
Comment #9
sunLet's do this.
We don't need an installer requirement here, we can simply rename the example.sites.php into sites.php.
Comment #10
sunMinor adjustments.
Comment #11
pillarsdotnet CreditAttribution: pillarsdotnet commentedHow may site admins provide custom
sites/sites.php
files without hacking core and/or being overwritten by core upgrades?Comment #12
sunHm. You're right. But without a sites.php and this adjustment for conf_path(), you're not able to install Drupal in the first place.
Chicken and egg situation, kinda.
I like the direction of this patch though. The entire magic and string building/conversion (of HTTP port, subdirectory, etc) that currently happens to auto-determine the sites directory really ought to be replaced with less magic and concrete mappings/definitions in sites.php. Mappings should be precisely declared (and we could add some wildcard support to that), and you even have the $http_host and $script_name variables to define dynamic mappings on your own.
Comment #13
pillarsdotnet CreditAttribution: pillarsdotnet commentedSo the installer should create a sites.php file (or warn of its nonexistence) in the same way that it now creates (or warns about) a settings.php file?
Comment #14
catchDiscussed this with webchick in irc ages ago but never posted to the issue. The idea has been floating around, I think from quicksketch, to get rid of sites/all/modules sites/all/themes and go back to having root level module and themes (now that /core means things aren't all mixed in any more).
This could be extended to having settings.php in the root directory as well, always available.
The multisite logic then we could force to only kick in if there's a $multisite = TRUE; in settings.php - at which point it would then look up the site-specific settings.php either via sites.php or the file system discovery. I think it's OK to require a single flag in settings.php (or sites.php) to have multi-site work, less sure about requiring the sites array, especially since #1055856: Optimize settings.php discovery removes all the i/o lookup for sites that have sites.php set up correctly already.
Comment #15
Crell CreditAttribution: Crell commentedRather than requiring sites.php, couldn't we just say that multi-site is only enabled if you have sites.php? If you don't, then sites/default is all you get (well, plus sites/all). No directory scanning at all. If you do have sites.php, then use that map instead of directory scanning. Make all directories keywords, not magic-naming based on domain.
That does still leave in the on file_exists() for sites.php itself, but I'm not super worried about that. It still saves us a fair bit of logic that almost no one uses.
Comment #16
catchquicksketch had an idea to have a settings.php in site root that's required for every site. If you want multisite then you put $multisite = TRUE; in settings.php and the logic kicks in. (the other part of this would be ditching sites/all and re-introducing top level module and theme directories, except for contrib/custom modules this time now that core code is all in /core).
That's similar to both ideas but means a bit more jiggling things around.
Comment #17
sunI'm sorta working on that already. #562042: Search for install profiles in sites/[all|site]/profiles folders, and move core profiles into /core/profiles is the key patch to allow for that (possible) change.
Aside from that, I like both suggestions in #15 and #16. I agree we shouldn't perform all of that rather expensive site detection and directory scanning unless a flag isn't enabled somewhere.
Comment #18
sunTo continue on #17, I've created:
#1724252: Allow and encourage top-level directories instead of /sites/all/* directories
Comment #19
webchick+1 to #15 or #16 instead of the proposal in the issue title. sites.php (and multisite) is weird, and I'd rather only foist it on someone who needs that level of complexity.
Comment #20
sunKISS.
Comment #21
sunClarifying issue title, and tagging for architectural review.
Also, sorry, need to remove that "i/o" since the slash in it completely hi-jacks D6's taxonomy term autocomplete handler.
Comment #22
meba CreditAttribution: meba commentedNote tat I am sure there are people using 'catch all' method for extra large installations - as long as sites/domain.com exists, it works. It should still be possible to use something like a wildcard?
Comment #23
cweagans+1 for #20. Simple and to the point, and it doesn't add any unnecessary complexity for users that do want the multisite functionality.
Comment #24
Crell CreditAttribution: Crell commentedHonestly, I'm happy to eliminate it entirely. I never actually understood it, and it's incompatible with dev/staging/prod domains anyway.
16 days to next Drupal core point release.
Comment #25
sunWell, @meba made a good point in #22 for why we might want to keep it.
It essentially allows you to do one of these two things:
A) Use a
sites.php
array key containing 'example.com'B)
sites/example.com
...as a wildcard/catch-all site to route any subdomain into the example.com site.
So let's keep that for now -- the idea is to only opt-in into the multi-site functionality anyway; there's not really a need to change/destruct the actual current multi-site behavior/functionality, at least not as part of this issue. ;)
Comment #26
Crell CreditAttribution: Crell commentedFair enough, follow-up issue. We still end up skipping it in the 99% case anyway.
Comment #27
sunQuick adjustment: Removed the @todo, since I think it's bogus/irrelevant/needless.
Comment #28
sunThat said. The entire string-futzing and concatenation of $confdir in there is weird and needless.
The
$confdir
variable dates back to a time in which this site detection code was part ofdrupal_settings_initialize()
, in which we are purposively setting the$confdir
variable, so that it can be used withinsettings.php
.That
$confdir
variable is needless insites.php
, since it only ever contains"sites"
, and becausesites.php
is only supposed to return a domain-to-sitename mapping in the$sites
array.Comment #29
webchickHm. I'm not sure about $confdir being needless. We should run that past a few Drupal hosting companies. Barry Jaspan and Matt Cheney will both be at DrupalCon.
I'd prefer to keep this patch to only the minimum necessary to implement the change, personally, and discuss further optimizing the multisite pipeline elsewhere.
Comment #30
webchickSent an email out to Barry, Matt, and David Strauss, and directed them here to review this patch.
Comment #31
webchickAlso, unless I'm doing something wrong (always possible), this patch seems to break the installer (at least in the UI).
Can anyone else confirm?
Comment #32
bjaspan CreditAttribution: bjaspan commented(Wow, something is broken with the CSS for this page; the edit-comment-wrapper div is position:absolute, right on top of the rest of the comment form. Firebugging out the position:absolute makes everything useable again.)
Here are some thoughts.
It must be possible for the hosting environment to provide database credentials from outside of settings.php; users should never have to know or care what their db server/name/creds are. I believe Pantheon provides this info via environment variables, and Pressflow is patched to look for them there (I think David submitted a D8 patch for this). On Acquia Cloud, we provide an include file that we add to sites/default/settings.php on site import that loads the appropriate db creds for the environment (dev/test/prod) of the current page request. We support multi-site, so we provide a separate include file for each set of databases. e.g. If you create dbs site1 and site2 for multi-sites site1.com and site2.com (which means you have six actual mysql db instances, dev/test/prod for each), we provide two settings include files, site1-settings.inc and site2-settings.inc, that point to the correct db instance for the current page load. However, in that case, it is up to the user to create sites/site1.com/settings.php and include site1-settings.inc from there.
Cloud assumes that all settings.php files will exist in sites/*/settings.php, and we treat any such directory as a site directory: we create a files directory in our network filesystem for it, and symlink sites/*/files to it. It's a hack, of course. I'd be much happier to have a definitive way to know exactly what sites directory the site thinks exists, where its settings.php file is, what domain name(s) it is for, etc. Today, sites.php is optional. If we made it mandatory that it exist and list all possible domain names and directories containing settings.php, that would enable more intelligent/useful hosting functionality for supporting multi-sites.
Happy to talk more about this in Munich.
Comment #33
Crell CreditAttribution: Crell commentedBarry, is that a verbose +1 to #27 or #28? :-)
Comment #34
David StraussAngie emailed me. I've looked over #28 and Barry's comments. This looks good to me, especially from a "convention over configuration" perspective.
As Barry mentioned, I'd really like to get environmental variable configuration support into core, but this hardly makes that any harder.
Comment #35
naxoc CreditAttribution: naxoc commentedThere is work going on over in #760992: Where should site specific modules, themes and settings be kept? using some of the principles from this issue.
Comment #36
sunOk, so it seems like the change proposal is signed off.
However, @webchick is right in that this patch breaks the installer in some weird ways.
(I also managed to kill my dev site, since I forgot to create sites.php before testing the multi-site installer, hah! :))
Comment #37
sunUm. For some reason, I can't reproduce that issue anymore. Tried several installs for the default site and a multi-site, and they are working fine.
The cause seems to have been the missing sites.php file, which obviously screwed up the installer for me.
So I actually think we're back to RTBC, but it would be great if someone else could confirm this once more.
Comment #38
aspilicious CreditAttribution: aspilicious commentedSun, can you or someone else post steps to do the manual testing. It could be done by people attending core office hours.
Comment #39
sunHm. I'd love to, but testing this is a bit more complex, as you need to set up additional DNS/host names and virtual hosts on your local machine, so the multi-site functionality is actually triggered... :-/
/sites/one.drupal.local/
directory/sites/example.sites.php
into/sites/sites.php
(without changes)/sites/one.drupal.local/
./sites/sites.php
to add/sites/whatever/
directory/sites/whatever/
.I hope these steps are correct as I did not perform them manually.
Comment #40
danillonunes CreditAttribution: danillonunes commentedI have a local environment with an custom automatic DNS/virtual hosts (actually Nginx http servers) setup, so I did the tests as following:
Comment #41
tstoecklerSo reading that, this means the following problems exist with the current patch:
1. Conditions:
- the sites/default folder is hit by the 'example.com' domain.
- sites.php exists.
- sites.php has a
$sites['sub.example.com'] = 'this-directory-doesnt-exist';
entry, i.e. a domain pointing to a non-existing directory.Expectation: An error is shown, because sites.php is corrupt. I guess simply throwing an exception (without catching it) should be fine.
Actual result: The sites/default site, or example.com site, is shown.
2.
- the sites/default folder is hit by the 'example.com' domain.
- sites.php exists.
- sites.php has a
$sites['sub.example.com'] = 'this-directory-exists-but-is-empty';
entry, i.e. a domain pointing to a directory, which contains no settings.php.Expectation: The installer is shown to install the sites/this-directory-exists-but-is-empty site, or sub.example.com site, is shown.
Actual result: The sites/default site, or example.com site, is shown.
The fact that you get the example.com site if you hit sub.example.com with no entry in sites.php at all is actually wanted behavior.
Comment #42
sun@danillonunes: Awesome, thanks! :)
Even though you have some "FAIL"s (hah, great!) in there, I actually consider that as a positive test result for this patch, since we're not touching the actual site discovery process at all. It's perfectly possible that some of the expectations I stated are "my own" and do not actually match what the site discovery process is doing ;)
The important part is really just:
1) You were able to install.
2) You were able to enable multi-site handling after providing sites.php and install a second site.
So... I think it is safe to move this back to RTBC, since the only remaining task was to perform manual testing to make sure the multi-site functionality still works. And it does. :)
Comment #43
sunHm. Not completely sure whether @tstoeckler's comment was/is in line with mine - is it, or not?
Comment #44
tstoecklerI guess you're right. I do think those are legitimate bugs, though, I think we should at least open follow-ups for that. Marking back to RTBC.
Comment #45
webchickOk, this seems to have been reviewed both conceptually by people with advanced needs, and through manual testing. I agree we should create follow-ups for the items identified in #40 and #41. Next logical step is #1757536: Move settings.php to /settings directory, fold sites.php into settings.php and then, unless I'm mistaken, I think we're done with Ye Great File Shufflage Of 2012? :)
Committed and pushed to 8.x.
We'll need a change notice for this.
Comment #46
sun@bjaspan + @David Strauss: Is there an issue already for the "hosting provider databases/settings.php override" of #32 already? I've learned what Pantheon is doing there and can only guess that Acquia's approach looks similar. I'd love to investigate and help to find a native/built-in solution in core to improve your situation, since I believe that hosted platforms are corner-stone for Drupal's adoption and success. Would be great to have a dedicated issue to discuss that.
Comment #47
webchickWe are now over thresholds on critical tasks, so this and other issues with outstanding change notices are blocking features in D8. Please fix.
Comment #48
Crell CreditAttribution: Crell commentedChange notice added.
Comment #49
tstoecklerHere's the link:
http://drupal.org/node/1792924
Comment #50
Crell CreditAttribution: Crell commentedIt's also automatically added to the issue summary. :-) Also, I figure that notice can be edited in place once #1757536: Move settings.php to /settings directory, fold sites.php into settings.php gets sorted out.