Drupal can run multiple separate websites from a single codebase. In a Drupal multisite architecture, the individual websites share code (the Drupal core, modules, and themes), but each website has its own database so they do not share content, configuration, settings, or displayed themes.
A multisite configuration can help you with global website management tasks, such as website upgrades, since you must only upgrade one codebase. Running multiple websites from the same codebase can multiply problems, such as security issues, across all your websites. For a more robust solution, consider Site Factory.
To create a Drupal multisite:
- Sign in to the Cloud Platform user interface and select your application.
- Create an additional database for your new website.
Create an additional domain for the new site. For more information, see Managing domains.
Drupal uses the selection rules based on the multisite aliasing file
sites/sites.php
, which must be present to map multiple domains to specific directories. Drupal loads the optional settings in this file. The aliases in the array$sites
overrides the default directory rules. For more information about configuring this file, see default.settings.php.- Configure your aliases based on the
sites/example.sites.php
file. - In your local code repository, go to your
[docroot]/sites/
directory, and copy the/sites/example.sites.php
file tosites.php
in that directory. Edit
sites.php
to include an entry for each of your websites, mapping the website directory to the URL. For example, for a website with the URLemea.example.com
and the website directory[docroot]/sites/europe
, add the following line:$sites['emea.example.com'] = 'europe';
For more information, see Using sites.php to specify an alternate settings.php file.
- Create a new folder in
/sites/
by using the database name that you created earlier. - Copy the
/sites/default/default.settings.php
file to your new website’s subdirectory, and rename it tosettings.php
. In the Cloud Platform user interface, go to the Databases page, and click PHP to display the include statement (also called the require statement) for your website.
Copy the include statement to the clipboard.
- Edit the
settings.php
file in the new website’s subdirectory, and then paste your website’s include statement to the end of the file. Commit the changes to the new website’s
settings.php
file (and, if applicable,sites.php
file) to Cloud Platform:In the following Git commit, the
-a
option commits all the changes you made to the workspace. To commit only a specific file or directory, replace-a
with the name of the folder or directory.git commit -a -m "Added settings.php [and sites.php] for new website."
The
commit
command in Git only commits your changes to your local clone of the repository. To push those changes up to your Cloud Platform website for deployment, use thegit push
command to push the changes to the appropriate branch. For example, when deploying from a branch namedmaster
, use the following command:git push origin master
Some Drupal distributions may have a
.gitignore
file as in the following example:# Ignore configuration files that may contain sensitive information. sites/*/settings*.php
Delete this line if it is present, because it prevents you from committing your website’s
settings.php
file. As an alternative, use thegit add -f settings.php
command to force the code commit.- In your browser address bar, enter
[site_URL]/install.php
(where[site_URL]
is the URL of the new website), and press Enter. Continue with the standard Drupal installation procedure.
If you run a Drupal multisite on Cloud Platform, you can add settings.php
files to as many [docroot]/sites
subdirectories as you need. Any domains for which you do not create a subdirectory fall back to the [docroot]/sites/default/settings.php
file and load the default website.
Creating a multisite in a subdirectory of a domain
If you have a Drupal installation for a domain name (for example, example.com
) and you would like to create another website in a subdirectory of the same domain (for example, example.com/subsite
), the multisite configuration process is somewhat different.
- Ensure you have defined
example.com
on your Cloud Platform Domains page. You do not need to add domains with the subdirectory appended. - Add a new database for your multisite, if you have not already done so. See Working with databases for more information.
- Add a multisite subdirectory to the
/sites
directory, as described in step 3 in the preceding procedure. In our example, you would name the multisite directory something like/sites/example.com.subsite
. - On the Databases page, click PHP for the Cloud Platform require statement for the new database. On your infrastructure, copy the default
settings.php
file from the/sites/default
directory and add the Cloud Platform require statement. Create a symlink in your docroot, linking the subdirectory name up one level, to the docroot. For our example, create the symlink by executing the following from the command line while in the
/docroot
directory:ln -s ../docroot subsite
- Add and commit the symlink and your multisite directory to your code repository.
After the changes propagate to the infrastructure, you can access your website at example.com/subsite
. If you must import a database, do that as well, or visit example.com/subsite/install.php
to install a new Drupal website.