1

I want to have one Drupal website codebase and one apache server instance, but have each country (domain) have it's own database.

Practical example:

I want all content to be completely separated from each other. One country doesn't have access to another countries database. I want to avoid having to add a new content type 9 times because I have 9 different databases. How can I fix this problem?

2

It is pretty simple to set up a multi-site with a single codebase. You could have the following directory structure (source):

-- core

-- modules
   -- contrib
   -- custom

-- themes
   -- contrib
   -- custom

-- sites
   -- site1.com
         -- modules
            -- custom
            -- contrib
         -- themes
            -- custom
            -- contrib
         -- files
         -- settings.php
   -- site2.com
         -- modules
            -- custom
            -- contrib
         -- themes
            -- custom
            -- contrib
         -- files
         -- settings.php
   -- site3.com
         -- modules
            -- custom
            -- contrib
         -- themes
            -- custom
            -- contrib
         -- files
         -- settings.php

The directories

--core

-- modules
   -- contrib
   -- custom

-- themes
   -- contrib
   -- custom

will be available to all your sites.

It is the

-- sites

directory that is responsible for the multisite. Take -- site1 as an example:

The modules, themes, and files for the site1 could stay in this directory. What is not mentioned in the documentation is the use the settings.php file. Each site could have its own settings.php file. This is typically a copy of sites/default/default.settings.php. This also means that each site could have its own database. And the entry for the database is made in the $databases array inside their respective settings.php files.

If you want to share config:

The steps that could be followed:

  1. Point the virtual host (domain) for site1.com to the Drupal root, i.e. the directory which has core, modules, themes, etc.
  2. Visit site1.com and install Drupal normally.
  3. Edit the sites/site1.com/settings.php to add the location of the directory where you wish to save the configuration yml files using the variable $config_directories[CONFIG_SYNC_DIRECTORY] = '<RELATIVE_PATH_TO_DIRECTORY>';
  4. Export configuration using Drush - drush cex. This will export complete configuration in the configured sync directory.

For site2.com and more subsites:

  1. Dump the database of site1.com and clone it to a new database to use as a database for site2.com. Cloning the exact same database is important as the configuration management works on cloned sites and not freshly installed ones. This is because the site's UUID needs to be the same.
  2. Have the value of the cloned database in sites/site2.com/settings.php. This means you do not have to install Drupal again. Just using the database of an already installed Drupal site.
  3. Copy the variable $config_directories[CONFIG_SYNC_DIRECTORY] along with its value from sites/site1.com/settings.php to sites/site2.com/settings.php. This will let you use the same configuration for site2.com as well.
  4. Follow steps 1-3 above to create more multi-sites.
  • Thanks very clear answer! If I don't want to have a certain setting shared (example: locale settings), should I just git ignore the specific setting file? Or what would be the best way to go about that? – Yassin Tahtah Nov 3 '18 at 10:33
  • @YassinTahtah - There is no straightforward way (yet) to do it just using drupal core. Your best bet could be using the contrib modules config_split and config_filter. – AjitS Nov 12 '18 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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