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:
- Point the virtual host (domain) for
site1.com
to the Drupal root, i.e. the directory which has core
, modules
, themes
, etc.
- Visit
site1.com
and install Drupal normally.
- 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>';
- Export configuration using Drush -
drush cex
. This will export complete configuration in the configured sync directory.
For site2.com and more subsites:
- 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.
- 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.
- 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.
- Follow steps 1-3 above to create more multi-sites.