Skip to content

Installation

Install Sites with Composer, enable it, and let Drupal accept the hostnames of your sites.

Requirements

Get the code

composer require drupal/sites

The package holds the sites module, its submodules and two recipes. Satellite modules are projects of their own; Modules names the project of each.

Sites, Environment Context and Views Query are published as beta and release candidate versions. If your composer.json sets "minimum-stability": "stable", set it to "beta" and keep "prefer-stable": true.

Enable the modules

drush en sites_content

This enables sites and sites_content, and with them Sites UI (the admin pages under /admin/sites), Sites menu (per-site menus) and, when Taxonomy is installed, Sites taxonomy.

Also enable:

  • the core Navigation module (navigation): the site switcher, the preview controls and the content override actions live in its top bar;
  • Sites Metatag (sites_metatag, needs Metatag): the canonical and hreflang links of content that several sites show.

Without them, the status report at /admin/reports/status shows a warning. Sub-sites, languages and URL aliases per site come from further submodules (Modules).

Or apply a recipe

Instead of drush en, apply a recipe from the web root:

php core/scripts/drupal recipe modules/contrib/sites/recipes/sites_base
Recipe Sets up
sites_base The same modules as drush en sites_content.
content_sites sites_base, Sites Pathauto (needs Pathauto) and Sites taxonomy. A site type Site whose sites hold the articles, basic pages, tags and users of the Standard profile and offer the roles Content editor and Administrator. An enabled Example site on example-site.ddev.site: change its hostname or delete it.

Trust the hostnames

Sites picks the site from the hostname of each request, so settings.php must limit the hostnames Drupal accepts. The sites entry stands for the hostnames of all sites; the hub's own hostname needs a pattern of its own:

$settings['trusted_host_patterns'] = [
  '^admin\.example\.com$',
  'sites' => '.*',
];

Drupal accepts any hostname through the sites entry; Sites then accepts only the other patterns of the list and the hostnames of the sites, with their aliases and language domains, in every environment. A site created later is trusted at once.

Without trusted_host_patterns, the status report shows the error Sites: trusted host patterns. More on hostnames: Hostnames and sub-sites.

Result

/admin/sites lists the sites. Add a site type, then create a site, or follow the Quick start. A platform administrator needs both Administer sites and Administer sites configuration (Permissions).