Configuring settings.php

Last updated on
1 November 2018

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

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.

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.

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 one of the Single Sign On solutions.

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:

Help improve this page

Page status: No known problems

You can: