Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When settings.php is a symbolic link, services.yml and settings.local.php are not included. The reason is the usage of __DIR__ to resolve the site path. In case of a symlink, __DIR__ returns the real path of settings.php.
Comment | File | Size | Author |
---|
Comments
Comment #2
mkalkbrennerThis patch for default.settings.php solves the issue (for new installations).
Comment #3
cilefen CreditAttribution: cilefen commentedThis is interesting. Can you look over the issue priorities and evaluate if this is really major? It could be, but its effect is limited to sites who made a symlink and generally know they did it.
Comment #4
mkalkbrenner@cilefen:
Yes, I think it's a least major. Personally I consider this bug as critical because I ran into this issue on an existing Drupal 8 production site!
The site was up and running with a services.yml it randomly picked up in the folder where the symlinked settings.php file physically resists. And this services.yml was different from the one that existed in sites/default. That's how I discovered the issue.
So, the assumption that "its effect is limited to sites who made a symlink and generally know they did it" has already be proven to be wrong.
Comment #5
star-szr@mkalkbrenner first of all thanks for this report.
Discussed this issue with @alexpott @xjm @catch @effulgentsia.
DRUPAL_ROOT
is effectively a global and we are trying to avoid using them, see #2328111: Replace most instances of the DRUPAL_ROOT constant with the app.root container parameter for some more background. Not sure what the fix here should be but potentially it could be adding documentation to default.settings.php. #2280383: FIx settings.local.php after new bootstrap is the issue that actually changed the settings.local.php include fromDRUPAL_ROOT
to__DIR__
and I think one of the goals there was to reduce fragility. It looks like #2381763: Adjust the order of container yamls to override settings per environment is where the services.yml reference in default.settings.php was added (I think that line of code has always been using__DIR__
).It would be nice to know more about your hosting setup or just more about how you ran into this situation. In #4 I can't tell if you set up the symlink or not or if it was a result of a hosting provider's infrastructure or similar. If you can provide any information about what steps you used to troubleshoot that may also be helpful in determine the priority of this issue. Thanks.
Comment #7
mkalkbrennerYes, #2280383: FIx settings.local.php after new bootstrap introduced this issue. The real fix for that issue would have been to replace $conf_path by $site_path, what I did now. The people who discussed that issue two years ago were probably not aware of problem related to __DIR__ and symlinks.
From comment #3 in that issue:
The symlink is in the same directory! But __DIR__ resolves the symlink and therefor it leads to a jump to a different directory in our case. See http://php.net/manual/en/language.constants.predefined.php
Since Drupal 5 we use such symlinks. We have multiple settings files, one per environment (dev, testing, staging, production). Due to the fact that this file contains passwords, these files do not resist in the standard code repository a normal developer can access. They're located in a different repository and are therefor deployed in different directories on the servers. For Drupal 5, 6 and 7 symlinking settings.php was no problem.
Comment #8
hchonovExchanged DRUPAL_ROOT with $app_root as mentioned in #5.
Comment #10
hchonovWrongly named interdiff-2-8.patch, it should've been interdiff-2-8.txt...
Comment #11
hchonovComment #12
cilefen CreditAttribution: cilefen commentedThis comment change is unnecessary.
Comment #13
hchonov@cilefen like you said.
Comment #16
hchonovComment #18
tstoecklerThis makes a lot of sense.
settings.php
itself is required with the following:And that is also used in e.g.
example.local.settings.php
.Comment #19
alexpottCommitted 44adac7 and pushed to 8.3.x. Thanks!
Committed 8af9db2 and pushed to 8.2.x. Thanks!
I checked that $app_root is defined when settings.php is run and it is.
Comment #23
arsn CreditAttribution: arsn commented