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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mkalkbrenner created an issue. See original summary.

mkalkbrenner’s picture

Status: Active » Needs review
FileSize
982 bytes
cilefen’s picture

For this to be major there would be no workaround. But if sites.php works, this should be normal priority.

Status: Needs review » Needs work

The last submitted patch, 2: 2857304.patch, failed testing.

mkalkbrenner’s picture

For this to be major there would be no workaround. But if sites.php works, this should be normal priority.

Setting 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.

cilefen’s picture

Fair enough!

frankherrman’s picture

When 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.

mkalkbrenner’s picture

Meanwhile 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.

mattjones86’s picture

Why 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...

cilefen’s picture

One can edit the docs and link to this issue.

gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
1.86 KB

Status: Needs review » Needs work

The last submitted patch, 11: 2857304-11.patch, failed testing.

mkalkbrenner’s picture

The update from PHP 7.0.19 to 7.0.20 broke the work-around posted in #8!

mkalkbrenner’s picture

It'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

mattjones86’s picture

@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.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

daften’s picture

For 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.

daften’s picture

Status: Needs work » Needs review
FileSize
2.08 KB

I was wrong, we just need to update the outer loop. Updated patch in attachment.

Status: Needs review » Needs work

The last submitted patch, 21: 2857304-21.patch, failed testing. View results

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

allanforms’s picture

I 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

    <Directory /var/www/html> #drupal root
	Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

/var/www/html/sites/sites.php

$sites['www.example.com'] = 'www.example.com';
$sites['123.123.123.123'] = 'www.example.com';
$sites['www.example.com.new_site'] = 'www.example.com.new_site';
$sites['123.123.123.123.new_site'] = 'www.example.com.new_site';

/var/www/html/sites/www.example.com.new_site/settings.php

$config['system.logging']['error_level'] = 'verbose'; #just to check the errors, but couldn't get around them

And inside drupal root

root@server:/var/www/html# ls -la
... (stuff)
lrwxrwxrwx  1 www-data www-data      1 Jul 15 11:09 new_site -> .
... (more stuff)

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.

jvandyk’s picture

The 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):

<Location "/site1" >
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ /site1/index.php [L]
</Location>

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.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

gerzenstl’s picture

I 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?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.