4

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?

3 Answers 3

1
  • 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 [email protected]
    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/
    
1
  • 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, 2016 at 15:39
0

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

$ drush site-install --db-url=mysql://db_user:[email protected]/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

0

If you really want to make your life easy, use Aegir. It does all of this automatically via point and click. From the official Drupal documentation on multisite:

It should be noted, however, that using the Aegir hosting system is preferred. It does all of the heavy lifting for you using secure best practices including automatically configuring virtual hosts for both Apache and Nginx, adding HTTPS support, running Composer commands, etc. See the documentation for setting up a "platform", Aegir-speak for a multisite codebase.

For your use case, you'll need to enable the (Site) Subdirectories module, which ships with core Aegir.

No command-line work is necessary at all as this is all done for you in the back-end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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