Problem/Motivation
According to Multisite Mapping with Drupal It is possible to create a multisite setup without symlinks that is based on paths, for example
http://dev.example.com/site1
http://dev.example.com/site2
But the code that should handle that scenario is completely broken:
// Otherwise, use find the site path using the request.
$script_name = $request->server->get('SCRIPT_NAME');
if (!$script_name) {
$script_name = $request->server->get('SCRIPT_FILENAME');
}
...
$uri = explode('/', $script_name);
SCRIPT_NAME always returns index.php and SCRIPT_FILENAME returns the real path in the file system which is obviously the same for site1 and site2 as long as you don't create any symlinks and virtual hosts for every site. According to the documentation that was the case for Drupal 7 and that's where the code comes from:
By sharing the same drupal code base as above (/public_html/drupal) , you may extend the Subdomain Mapping where you can set another drupal sites under URL's Paths like so:
http://dev.example.com/site1,
http://dev.example.com/site2, etc..Symbolic Links
First you will need to access your server shell. Then create the symbolic links to the drupal root folder named site1 and site2 by following command:
$ cd /path/to/your/public_html/drupal
$ ln -s . site1
$ ln -s . site2
For Drupal 8 the documentation states something else (which makes a lot of sense):
Multi Drupal Sites (By Drupal 8)
By Drupal 8 the symbolic links are no more required, there even a flexibility to name the folders under /public_html/drupal/sites as long you put them on the file sites.php like:
$sites = array(
'dev.example.com' => 'dev',
'dev.example.com.site1' => 'dev.site1',
'dev.example.com.site2' => 'dev.site2',
);
Proposed resolution
In Drupal 8 the algorithm must simply use REQUEST_URI instead of SCRIPT_FILENAME.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#21 | 2857304-21.patch | 2.08 KB | daften |
#11 | 2857304-11.patch | 1.86 KB | gaurav.kapoor |
#2 | 2857304.patch | 982 bytes | mkalkbrenner |
Comments
Comment #2
mkalkbrennerComment #3
cilefen CreditAttribution: cilefen commentedFor this to be major there would be no workaround. But if sites.php works, this should be normal priority.
Comment #5
mkalkbrennerSetting the "path" in sites.php doesn't work and there's no workaround if you can't configure the webserver by yourself. So I think the priority is correct.
Comment #6
cilefen CreditAttribution: cilefen commentedFair enough!
Comment #7
frankherrman CreditAttribution: frankherrman at Typify commentedWhen I use REQUEST_URI it does point to the right sites-folder, but I'm still ending up with a 404 error. I think this is because the routing system checks for /site2/[somepath] to find the correct node instead of /[somepath]/. I did not find the corresponding code yet though.
Comment #8
mkalkbrennerMeanwhile I read a lot of code. What is still working is a (weird) symlinking like described for drupal 7 here.
Unfortunately there're many places that need to be changed to get the easy setup described in documentation for drupal 8 to work. But it seems to be achievable.
Comment #9
mattjones86Why is the bug not mentioned in the docs!?
Just spent an hour banging my head against the wall thinking I was doing something wrong!
https://www.drupal.org/docs/7/multisite-drupal/multisite-mapping-with-dr...
Comment #10
cilefen CreditAttribution: cilefen commentedOne can edit the docs and link to this issue.
Comment #11
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #13
mkalkbrennerThe update from PHP 7.0.19 to 7.0.20 broke the work-around posted in #8!
Comment #14
mkalkbrennerIt's not PHP but Apache 2.4.26 who breaks the SCRIPT_NAME in a setup like descriped in #8:
https://bz.apache.org/bugzilla/show_bug.cgi?id=61202
Comment #15
mattjones86@mkalkbrenner I'm not sure that's the issue, I think I was seeing the same problem with NGINX - though I can't be sure now because I've deleted the demo.
Comment #20
daften CreditAttribution: daften at Picabit commentedFor the patch from #11, don't we need to trim the starting slash from the request_uri? Otherwise the site will always go to the default site folder.
Comment #21
daften CreditAttribution: daften at Picabit commentedI was wrong, we just need to update the outer loop. Updated patch in attachment.
Comment #27
allanforms CreditAttribution: allanforms as a volunteer commentedI thoght I was damned!
Thank God I wasn't and found this bug report.
I'm running version 9.2.1 on www.example.com and tried to install a new site in www.example.com/new_site: it was almost impossible!
After following the official documentation and a bunch of tutorials online explaining how to do it I got stuck.
In a meeting with a friend from work we got around, but it was a little messy:
/etc/apache2/sites-enabled/default.conf
/var/www/html/sites/sites.php
/var/www/html/sites/www.example.com.new_site/settings.php
And inside drupal root
But after all the tries I got a broken installation, where I couldn't figure out what was wrong (after success installation I found out I didn't even get to the end of the installation)
Dropping and creating the database again and doing another installation finally made it, but I would love to just configure sites/sites.php and get it working out of the box!
I'm looking forward to this patch being released.
Comment #28
jvandyk CreditAttribution: jvandyk commentedThe patch in #21 tries to switch the basis of parsing back to REQUEST_URI, but Drupal switched from REQUEST_URI to SCRIPT_NAME because REQUEST_URI is user-provided data.
You can use mod_rewrite to make sure that the subpath is prepended to SCRIPT_NAME by creating a Location in the Apache vhost for the domain in which you want subpaths (if you're using Apache):
This causes the value of SCRIPT_NAME to be /site1/index.php instead of /index.php, allowing findSitePath() to parse it and subsequently find its entry in sites.php.
Comment #32
gerzenstl CreditAttribution: gerzenstl at 42mate commentedI believe that instructions for Multisite setup based on paths are incomplete or maybe needs more work.
I was able to make this work with D9 and NGINX, but I needed to read not only the docblock in sites.php and the docs. I also read several blog posts to understand how to set virtual host to work with this approach (and I'm still looking if there is a way to avoid using symbolic links).
I think the current issue where is tracked the documentation improvements is this one. Are there any other issue mentioning something about this multi-site approach?