Last updated 18 January 2017. Created on 18 March 2011.
Edited by agentrickard, add1sun, ar-jan, DarrellDuane. Log in to edit this page.

Remember, the Domain Access module lets you run multiple sites from a single installation. You only need one settings.php file. As a result, some options in your settings.php file need to be considered carefully.

Drupal 8

These instructions do not apply to Drupal 8. Please see the README.md files for each module in the download.

$base_url

The $base_url setting is normally not set. With Domain Access, you cannot set this value manually.

Since multiple domains are involved, Drupal needs to be allowed to set this value. (For the technical, this happens in the conf_init() function).

If you need to install Drupal in a subdirectory and wish to hide that subdirectory from site visitors, you may set $base_url dynamically. See the instructions at http://drupal.org/node/633726.

$databases (Drupal 7)

The $databases value allows for table prefixing of your Drupal database in the event that you run more than one site from a single database.

$databases can be used normally with Domain Access.

$db_prefix (Drupal 6)

The $db_prefix value allows for table prefixing of your Drupal database in the event that you run more than one site from a single database.

$db_prefix can be used normally with Domain Access. Note that the Domain Prefix module (included in the package for Drupal 6) allows for dynamic table prefixing via the UI. If you use Domain Prefix, normally you will not set $db_prefix, as that module will do it for you.

$cookie_domain

By design, Drupal cookies are set for the current website on login. That is, if you login from www.example.com, the cookie will be set from the domain 'www.example.com.'

However, a cookie from www.example.com is not valid on one.example.com. In order to provide for login across your active domains, you must set the $cookie_domain value to the string indicating your root domain.

Typically, this value is '.example.com'.

If your domains do not share the top-level, then you may need to login to each site separately or use a module such as Single Sign On.

NOTE: After you change your cookie value, you will need to logout and log back in for the new cookie to take effect.

Add settings.inc

This step is no longer required if using Drupal 8.

For Domain Access to work, you must add some code to your settings.php file. This code will load the Domain Access bootstrap routines that determine how your site is being requested.

If you do not add settings.inc to your settings.php file, Domain Access will fail to load and report an error message to site administrators.

IMPORTANT: You must add these lines to settings.php after $databases ($db_url in Drupal 6) has been set; otherwise, Drupal will fail to load. Normally, you should add these lines to the end of the settings.php file.

NOTE: If you perform a Drupal core version upgrade, you must remove these lines from settings.php. See UPGRADE.txt for details.

There is also a video tutorial that shows installation using Option 1.

Installation

In the Domain Access download, find the following file:

  • domain > settings.inc

You will need to load this file from inside your settings.php file. There are two methods for this.

Option 1 -- Preferred

This method is preferred, since any updates to the module release will be reflected in this file.

Drupal 7

Add the following lines to the end of your settings.php file:

/**
 * Add the domain module setup routine.
 */
include DRUPAL_ROOT . '/path/to/modules/domain/settings.inc';

In this case, change 'path/to/modules' with the directory where your modules are stored. Typically this will be 'sites/all/modules', which makes the lines:

/**
 * Add the domain module setup routine.
 */
include DRUPAL_ROOT . '/sites/all/modules/domain/settings.inc';

Drupal 6

Add the following lines to the end of your settings.php file:

/**
 * Add the domain module setup routine.
 */
include './path/to/modules/domain/settings.inc';

In this case, change 'path/to/modules' with the directory where your modules are stored. Typically this will be 'sites/all/modules', which makes the lines:

/**
 * Add the domain module setup routine.
 */
include './sites/all/modules/domain/settings.inc';

Option 2 (All versions)

If you are having difficulty determining the correct path, copy the following files into your settings folder.

  • domain > domain.bootstrap.inc
  • domain > settings.inc
  • domain > settings_custom_url.inc

The files should be in the same directory as your active settings.php file.

Then add the following lines:

/**
 * Add the custom_url_rewrite_outbound function.
 */
include 'settings.inc';

Testing Your Configuration

After editing your settings.php file, go to the Domains page (Drupal 7: Administration > Structure > Domains, or http://example.com/admin/structure/domain; Drupal 6: Administer > Build > Domains, or http://example.com/admin/build/domain). You may see a warning at the top of the page:

"Domain access failed to load during phase: bootstrap include. Please check your settings.php file and site configuration."

This message means that your PHP server cannot find the include file. You may need to test other path options for the include code.

When this occurs, the default domain will be loaded, but custom settings or themes for other domains will not.

If the module is working correctly and you are getting persistent errors due to web crawlers, you may disable this warning. To do so, edit settings.php and add the following lines to the bottom of the file:

$conf['domain_hide_errors'] = TRUE;

This will suppress the warning messages. See http://drupal.org/node/774692 for background.

Additional Resources

If you are having trouble configuring the include, you should check your PHP include path. You may need to use an absolute path to your server root.

http://us3.php.net/manual/en/ini.core.php#ini.include-path

You may also copy the entire function custom_url_rewrite_outbound() directly into your settings.php file.

custom_url_rewrite_outbound() (Drupal 6 Only)

custom_url_rewrite_outbound() is a special function that you can add to settings.php to alter how Drupal writes links to content. Domain Access implements this function within the context of the URL Alter module, which is a functional backport of changes implemented in Drupal 7.

If your site uses custom code to implement custom_url_rewrite_outbound(), consider upgrading to the URL Alter module for full compatibility. You may also call the function domain_url_rewrite_outbound() directly in your custom code.

NOTE: Domain Access does not use custom_url_rewrite_inbound().

For more information, see:

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

liquidcms’s picture

I find the section above on $cookie_domain in the area between very confusing and simply wrong. A few things above which are incorrect:

By design, Drupal cookies are set for the current website on login. That is, if you login from www.example.com, the cookie will be set from the domain 'www.example.com.'

the term "domain" is extremely inconsistent. I am not sure i have seen anyone refer to www.example.com as a domain, the domain (or FQDN) here would be example.com. Although, possibly Drupal does set the cookie as www.example.com

However, a cookie from www.example.com is not valid on one.example.com.

yes, from experience, i believe this to be correct

In order to provide for login across your active domains, you must set the $cookie_domain value to the string indicating your root domain.

what is an "active domain" and what is a "root domain"? Neither of these are common terms.

Typically, this value is '.example.com'.

oh, so you mean set cookie domain to your FQDN (is this what you refer to as "root domain"? In other words if you have sites as site1.example.com and site2.example.com then set your $cookie_domain to .example.com? I am pretty sure that will not work.

If your domains do not share the top-level, then you may need to login to each site separately

the term top level domain refers to .com in example.com; pretty sure that is not what is meant here.

Examples are always a good idea.. :)

Again, not 100% sure, but from experience i do this:

multisite install with sites at:
site1.dev.com
site2.dev.com
site1.live.com
site2.live.com
site1.mylocal
site1.tomslocal

i set $cookie_domain for all of these as the subdomain.fqdn as shown above, e.g.:

$cookie_domain = 'site1.dev.com';

The comments in the settings.php file suggest, i think, that this should be:

$cookie_domain = '.site1.dev.com';

i have never added the leading . but perhaps that would also work.