I followed this tutorial(Drupal 7) but it not worked for me(Drupal 8):

This is my enviroment:

  • CentOs 7 with SELinux(mode: enforcing)
  • Varnish 4.0.3
  • Apache 2.4.23
  • Drupal 8.2.4

I need to create the next structure of sites:

  • / <-- First site
  • /site2 <-- Second site
  • /site3 <-- Third site

In the file sites/sites.php i have:

$sites['localhost.site2'] = 'site2';
$sites['localhost.site3'] = 'site3';

In the directory sites/ i have:

  • default/
  • site2.localhost
  • site3.localhost

In the root of the drupal o have the next symlinks to .:

  • site2 -> .
  • site3 -> .

In my .htaccess file i have:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/site2/(.*)$
  RewriteRule ^(.*)$ /site2/index.php [L,QSA]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/site3/(.*)$
  RewriteRule ^(.*)$ /site3/index.php [L,QSA]

When i tried to access to each subsite, he shows me the default. What is wrong?

up vote 1 down vote accepted
  • Download latest D8 version.
  • Extract and navigate into the directory: /drupal/sites/
  • Create sites.php duplicating example.sites.php
  • Add the code to sites.php

    $sites = array( 'dogs.multisite.local' => 'dogs', 'multisite.local.cats' => 'cats', );

  • Create two folders named 'cats' and 'dogs' on the sites folder.

    /drupal/sites/dogs/
    /drupal/sites/cats/
    
  • The /drupal/sites/default/ site will have default files we need to copy into each of our sites. Copy these files using the cp command in the sites directory:

    cp default/default.settings.php dogs/settings.php
    cp default/default.settings.php cats/settings.php    
    cp default/default.services.yml dogs/services.yml
    cp default/default.services.yml cats/services.yml
    
  • Setup virtualhost

    hosts

     127.0.0.1  multisite.local
    

    httpd-vhosts.conf

    <VirtualHost *:80>
    ServerAdmin webmaster@multisite.local
    DocumentRoot "/opt/lampp/htdocs/drupal"
    ServerName multisite.local
    ServerAlias    *.multisite.local multisite.local.*
    ErrorLog "logs/multisite.local-error_log"
    CustomLog "logs/multisite.local-access_log" common
    </VirtualHost>
    
  • Once it is done, you can start the installation of your new website in a multisite context from the urls:

       http://dogs.multisite.local/
       http://multisite.local.cats/
    
  • I tried to do it only with the IP of the Virtual Machine, but it dont work. I need to do it with the hostname. Thanks for your help! – Lenin Meza Dec 21 '16 at 15:39

I suggest you to use drush. It will make your life way easier:

$ drush site-install --db-url=mysql://db_user:db_password@127.0.0.1/sample_site_db --sites-subdir=sample.subsite.com --yes

Please note that drush will generate all the proper config for you. Then you can check how it is actually when you want to go "manual".

And here you have a full list of steps to setup a Multisite on Drupal 8: https://evolvingweb.ca/blog/drupal-8-configuration-management-multi-site

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.