Multisite with Drupal 8

Scenario:

  1. main website - web.site
  2. subdomain - sub.web.site
  3. another domain - website.com

 

  1. about website.com
    we have to remove actual folder for this domain, presented in our server system
    rm -rf website.com {it will delete entire folder}

    ln -s web.site website.com {to point out WEB.SITE as target for finding drupal files}


     
  2. making deal with route folder for drupal 8 installation files {web.site/public_html}
    ln -s ./ sub {considering, we use subdomain SUB.web.site}
    [syntax for symlinks:
    ln -s source_file myfile]

     
  3. path: public_html/sites
    mkdir sub.web.site website.com


    cp example.sites.php sites.php

     
  4. nano sites.php {at the bottom}
    1)* URL: http://website.com
      $sites['website.com'] = 'website.com';
    * URL: http://sub.web.site
      $sites['sub.web.site'] = 'sub.web.site'; {also we can create folders with different names like simply 'SUB', but for not being confused it is better to leave the same full path in folder}


    either
    2)
    $sites = array(
       'web.site' => 'default',
       'website.com' => 'website.com',
       'sub.web.site' => 'sub.web.site',
    );

     - difference between drupal 7 and 8 also is - if you are not adept of drupal system, you have no option to direct drupal-system for setting up your installation
    Drupal_7: /admin/config/media/file-system -> gives an option for PUBLIC & PRIVATE paths
    Drupal_8: assumes, this option - to be modified only through settings.php
    during setup this folder is filled in.

     
  5. Copying SETTINGS & SERVICES files
    cp default/default.settings.php website.com/settings.php
    cp default/default.settings.php sub.web.site/settings.php
     
    cp default/default.services.yml website.com/services.yml
    cp default/default.services.yml sub.web.site/services.yml




     
  6. other settings according to drupal.org

    Multisite structure:

    -- core
    
    -- modules
       -- contrib
       -- custom
    
    -- themes
       -- contrib
       -- custom
    
    -- sites
       -- site1
             -- modules
                -- custom
                -- contrib
             -- themes
                -- custom
                -- contrib
             -- files
       -- site2
             -- modules
                -- custom
                -- contrib
             -- themes
                -- custom
                -- contrib
            -- files
       -- site3
             -- modules
                -- custom
                -- contrib
             -- themes
                -- custom
                -- contrib
            -- files
    
    

 

by virtue of: 1 - https://mediatemple.net/community/products/grid/204643210/how-do-i-use-s...
 2- https://www.ostraining.com/blog/drupal/drupal-multi-sites/
3 - http://www.kalose.net/oss/drupal-8-setting-multi-site/

 


USEFUL INFORMATION:

  1. Drupal 7 multisite - https://www.drupal.org/docs/7/multisite
  2. Drupal 8 multisite - https://www.drupal.org/docs/8/multisite

Enable per-site modules

In some cases, you may want one of your sites within your multisite to have its own modules. To enable this, you simply need to create the appropriate folders within the target site’s folder. In this example, we will enable site1 to have its own modules:

  1. Create a ‘modules’ folder in site1’s subdirectory: /d8multisite/sites/site1.d8multisite.com/modules
  2. Give apache write access to this folder with chown www-data /d8multisite/sites/site1.d8multisite.com/modules
  3. Test it out:
    1. Move out of site1’s subdirectory (i.e. into the root site) and install the pathauto module with drush drush dl pathauto
    2. Move into site1’s subdirectory and install the ds module with drush drush dl ds
    3. Visit both sites and confirm:
      1. Pathauto is available in both sites
      2. Display Suite is only available in site1

Installing virtual hosts for Drupal sites and subsites

The purpose of this guide is to concisely summarize how to implement apache vhost settings for each site or subsite.

All steps for this tutorial were implemented with Debian using Apache version 2.0.54.

Done!

  1. Gain entrance into your shell system, and su to root or another user that can edit apache2 configuration files.
  2. Go to your apache configuration files:
    cd /etc/apache2/sites-available
  3. Create a configuration file for your new site. For an example site, www.example.com, we make the site as such:
    nano example.com
    <VirtualHost *:80>
        ServerAdmin me@myserver
        DocumentRoot /home/web/drupal/
        ServerName www.example.com
        ServerAlias example.com *.example.com
        RewriteEngine On
        RewriteOptions inherit
        CustomLog /var/log/apache2/example.com.log combined
    </VirtualHost>
    <VirtualHost *:443>
        ServerAdmin me@myserver
        DocumentRoot /home/web/drupal/
        ServerName www.example.com
        ServerAlias example.com *.example.com
        RewriteEngine On
        RewriteOptions inherit
        CustomLog /var/log/apache2/example.com.log combined
        # SSL Specific options
        SSLEngine on
        SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
        SSLCertificateFile /etc/ssl/apache/CA.crt
        SSLCertificateKeyFile /etc/ssl/apache/CA.key
        SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
    </VirtualHost>
    
  4. Activate the site's configuration:
    a2ensite www.example.com
  5. Reload Apache's configuration:
    /etc/init.d/apache2 force-reload

If you get an apache error '/home/www/drupal5/.htaccess: Option Indexes not allowed here'
Assuming that my apache2 DocumentRoot is at /home/www,
and that drupal is linked to the doc root by
ln -s /usr/share/drupal5 /home/www/

add the following to /etc/apache2/conf.d/drupal.conf

<Directory /home/www/drupal5/>
Options +FollowSymLinks Indexes
AllowOverride All
order allow,deny
allow from all
</Directory>