Drupal can run multiple separate websites from a single codebase. 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. This style of architecture is known as Drupal multisite.
This configuration can be very helpful for global website management tasks, such as website upgrades, since you only have to upgrade one codebase. However, having multiple websites running from the same codebase can multiply problems, such as security issues across your websites. For a more robust solution, consider Acquia Cloud Site Factory.
To create a Drupal multisite, complete the following steps:
- Sign in to the Acquia Cloud interface and select your application
- Create an additional database for your new website.
- Create a new subdirectory in the
[docroot]/sitesdirectory with a name that will help you identify the website — for example,
- In your local code repository, go to your
[docroot]/sites/directory, and copy the
sites.phpin that directory.
sites.phpto include an entry for each of your websites, mapping the website directory to the URL. For example, for a website with the URL
emea.example.comand 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.
Drupal finds the correct website configuration directory by iteratively broadening matching URLs to domain names. For example, given the domain
test.foobar.baz.example.com, Drupal will check successively the following directories. For the website configuration directory, it uses the first one that exists and contains a file named
- Copy the
/sites/default/default.settings.phpfile into your new website's subdirectory, and then rename it to
- In the Acquia Cloud 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.phpfile 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.phpfile (and, if applicable,
sites.phpfile) to Acquia Cloud:
In the following Git commit, note that the
-aoption commits all the changes that you made to the workspace. To commit only a specific file or directory, replace
-awith the name of the folder or directory.
git commit -a -m "Added settings.php [and sites.php] for new website."
When you use Git, the
commitcommand only commits your changes to your local clone of the repository. To push those changes up to your Acquia Cloud website for deployment, use the
git pushcommand to push the changes to the appropriate branch. For example, if you are deploying from a branch named
master, use the following command:
git push origin master
Some Drupal distributions might have a
.gitignorefile that includes a line like this:
# Ignore configuration files that may contain sensitive information.
If it is present, delete the line, because it prevents you from being able to commit your website's
settings.phpfile. As an alternative, use the
git add -f settings.phpcommand to force the code commit.
- In your browser address bar, enter
[site_URL]is the URL of the new website), and then press Enter. Continue with the standard Drupal installation procedure.
If you run a Drupal multisite on Acquia Cloud, 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 will fall back to the
[docroot]/sites/default/settings.php file and load that 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 add another website that will be located in a subdirectory of the same domain (for example,
example.com/subsite), the multisite configuration process is somewhat different.
- Ensure that you have
example.comdefined on your Acquia Cloud Domains page. There is no need to add additional domains that have 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
/sitesdirectory, as described in step 3 in the preceding procedure. In our example, the multisite directory would be named something like
- On the Databases page, click PHP for the Acquia Cloud require statement for the new database. On your server, you should copy the default
settings.phpfile from the
/sites/defaultdirectory and add the Acquia Cloud 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
ln -s ../docroot subsite
- Add and commit the symlink and your multisite directory to your code repository.
After the changes have been propagated to the servers, you will be able to access your website at
example.com/subsite. If you need to import a database, you should do that as well, or visit
example.com/subsite/install.php to install a new Drupal website. You can also share database tables across a Drupal multisite.
- Using sites.php to specify an alternate settings.php file
- Multi-site Drupal at Drupal.org
- Multi-site - Sharing the same code base at Drupal.org