About Drupal multisite installations

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 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.

To create a Drupal multisite, complete the following steps:

  1. Sign in to Acquia, select your website, and then open the Databases page at Cloud > Databases. Create a database for your new website.
  2. The next step depends on which version of Drupal you are using. Drupal 6 requires a subdirectory in your [docroot]/sites directory that is named the same as the website's URL. For example, for a website with the URL www.example.com, you would need a directory at [docroot]/sites/www.example.com. Drupal 7 allows you to use either the Drupal 6 approach, or unique directory names that are mapped to the URL in the [docroot]/sites/sites.php file.
    • Drupal 7
      • Create a new subdirectory in the [docroot]/sites directory with a name that will help you identify the website, for example, [docroot]/sites/europe.
      • Go to your [docroot]/sites/ directory, and copy the /sites/example.sites.php file to sites.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 URL emea.example.com and the website directory [docroot]/sites/europe, add this line:

        $sites['emea.example.com'] = 'europe';

        For more information, see Using sites.php to specify an alternate settings.php file.

    • Drupal 6
      • Create a new subdirectory in [docroot]/sites based on your new website's URL, for example [docroot]/sites/mysite2.com.

    For both Drupal 7 and Drupal 6, 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 settings.php.

    • [docroot]/sites/test.foobar.baz.example.com
    • [docroot]/sites/foobar.baz.example.com
    • [docroot]/sites/baz.example.com
    • [docroot]/sites/example.com
    • [docroot]/sites/com
    • [docroot]/sites/default
  3. Copy the /sites/default/default.settings.php file into your new website's subdirectory, and then rename it to settings.php.
  4. Go to the Cloud > Databases page, and click Connect to database to display the include statement (also called the require statement) for your website.

    Display the require statement

    Copy the require statement to the clipboard.

  5. 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.
  6. Commit the changes to the new website's settings.php file (and, if applicable, sites.php file) to Acquia Cloud using the method based on your code repository:
    • Git

      In the following Git commit, note that the -a option commits all the changes that 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."

      When you use Git, the commit command 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 push command 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 .gitignore file that includes a line like this:

      # Ignore configuration files that may contain sensitive information.
      sites/*/settings*.php

      If it is present, delete the line, because it prevents you from being able to commit your website's settings.php file. As an alternative, use the git add -f settings.php command to force the code commit.

    • SVN

      If you are using SVN, the commit command commits your changes to the remote repository.

      svn commit -m "Added settings.php [and sites.php] for new website."
  7. In your browser address bar, enter [site_URL]/install.php (where [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.

  1. Ensure that you have example.com defined on your Acquia Cloud Domains page. There is no need to add additional domains that have the subdirectory appended.
  2. Add a new database for your multisite, if you have not already done so. See Managing your databases for more information.
  3. Add a multisite subdirectory to the /sites directory, as described in step 2 in the preceding procedure. In our example, the multisite directory would be named something like /sites/example.com.subsite.
  4. On your Cloud > Databases page, click the Configure settings.php button for the Acquia Cloud require statement for the new database. On your server, you should copy the default settings.php file from the /sites/default directory and add the Acquia Cloud require statement.
  5. 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
  6. Add and commit the symlink and your multisite directory to your code repository.

Once 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.

Sharing database tables across a Drupal multisite

You can also configure your installation to share database tables (such as the users, sessions, and profiles tables) across multiple websites. The procedure depends on your installed version of Drupal:

  • Drupal 7

    To share tables from a database across a Drupal multisite, retrieve the full name of the shared database and then assign it using the prefix array, as you would normally. For example, to use the drupal_shared database for users, sessions, and profiles, while using the mysite database for everything else, enter the following text in your websites' settings.php files:

    <?php
    // Use the mysite database as our default database, but delay connecting.
    $conf['acquia_hosting_settings_autoconnect'] = FALSE;
    require(
    '/var/www/site-php/mysite/mysite-settings.inc');

    // Use the drupal_shared database for users, sessions, and profiles.
    $shared = $databases['drupal_shared']['default']['database'] . '.';
    $databases['default']['default']['prefix'] = array(
     
    'default' => '',
     
    'authmap' => $shared,
     
    'profile_fields' => $shared,
     
    'profile_values' => $shared,
     
    'permission' => $shared,
     
    'role' => $shared,
     
    'sessions' => $shared,
     
    'users' => $shared,
     
    'users_roles' => $shared,
    );

    // Connect to the database.
    acquia_hosting_db_choose_active();
    ?>
  • Drupal 6

    To share tables from a database across a Drupal multisite, parse the path to the shared database and then assign it as you would normally using $db_prefix. For example, to share the users, sessions, and profiles for the database databasename across multiple websites, enter the following text in your websites’ settings.php files:

    <?php
    require('/var/www/site-php/mysite/mysite-settings.inc');

    $shared = substr(parse_url($db_url['drupal_shared'], PHP_URL_PATH), 1) . '.';
    $db_prefix = array(
     
    'default' => '',
     
    'authmap' => $shared,
     
    'profile_fields' => $shared,
     
    'profile_values' => $shared,
     
    'permission' => $shared,
     
    'role' => $shared,
     
    'sessions' => $shared,
     
    'users' => $shared,
     
    'users_roles' => $shared,
    );
    ?>

Maintaining cross-domain sessions with the $cookie_domain variable

If you have a Drupal multisite configuration where the additional websites are subdomains of the main domain (for example, www.example.com and multisite.example.com), you may want to keep the user session active when the user moves between the websites. All that is needed is to add the following line to settings.php, along with the shared database code:

$cookie_domain = '.example.com';

With this setting, you share the user tables between the websites and when a user signs in to www.example.com, they are signed in to multisite.example.com and vice versa.

This only works if each of the domains is on the same Acquia Cloud server and has the same second-level and top-level domain name. (For example, www.example.com and multisite.example.com works, if both are on the same server, but www.example1.com and myothersite.example2.com will not.) Otherwise, browser security policies will invalidate the session cookie.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
By submitting this form, you accept the Mollom privacy policy.