How to manage Drupal 8 multi-site configuration
Notes
You can set up each site with a separate subdomain on Platform.sh quickly with only a
few modifications to our Drupal 8 template.
First, you can modify your routes.yaml
file to assign a unique subdomain for each site.
We're going to use the subdomains first
and second
for the two sites, and reuse those
names throughout all of the following configuration steps. Notice how each subdomain is pointing at the same application,
called app
, as its upstream route.
Next, you can give each site its own config/sync
subdirectory, as well as settings in the
sites
subdirectory. To start off, each site's settings can be identical to those in
default
, but you can always customize them when you need to.
Each subsite, first
and second
has its own database and endpoint, so we will
give each of them a corresponding relationship in our .platform.app.yaml
file.
Each of those databases is defined for the same MariaDB instance in the project's services.yaml
file.
Notice that each database's relationship uses the service name db
but then includes the unique
endpoint defined for each of the two sites.
Once we deploy the application, we can see that each subdomain contains its own separate Drupal 8 installation.
We kept the subsite and endpoint names identical so that we could include some glue code that gets each installation
to talk to the right database. While we did not cover that code in this demo, it's relatively simple, so be sure to
check out our Drupal 8 Multisite template on GitHub for all of the details.
You can also take a look at our video on how to manage Drupal 8 multi-site configuration above.