Loading...


Related Products


Date Published: February 24, 2022

Using sites.php to specify an alternate settings.php file

Issue

You're running a multisite installation, and you need to map multiple domains to a multisite.

Resolution

The sites.php file can be used to do just that. With a multisite, Drupal will attempt to determine where the settings.php file for a requested domain is located. The documentation in the settings.php file explains this method well:

/* * The configuration file to be loaded is based upon the rules below.
* * The configuration directory will be discovered by stripping the
* website's hostname from left to right and pathname from right to
* left. The first configuration file found will be used and any
* others will be ignored. If no other configuration file is found
* then the default configuration file at 'sites/default' will be used.
* * For example, for a fictitious site installed at
* http://www.drupal.org:8080/mysite/test/, the 'settings.php' file is searched
* for in the following directories:
* 1. sites/www.drupal.org.mysite.test
* 2. sites/drupal.org.mysite.test
* 3. sites/org.mysite.test
* 4. sites/www.drupal.org.mysite
* 5. sites/drupal.org.mysite
* 6. sites/org.mysite
* 7. sites/www.drupal.org
* 8. sites/drupal.org
* 9. sites/org
* 10. sites/default 
* */


Configuring On The Acquia Platform

Drupal is good at determining what folder to route a request to, but there may be situations in which the default logic does not suffice. The goal of the sites.php file is to allow you to override this logic and specify a custom location for the settings.php file. The contents of the file are minimal, and you may set the logic. Inside of the sites.php file, you need to set an array called $sites.

The concept of sites.php, on Acquia hosting, is to have a single directory for Dev, Stage and Prod environments for each multisite: sites/sitename1 sites/sitename2 sites/sitename3 Each of these directories contains a settings.php file that is environment aware, using variables to correctly identify and interact with the database, and other aspects of the hosting environment. Into the sites/sites.php you would then identify the URLs that relate to that directory:

Dev Environment Domains

$sites['exampledev.prod.acquia-sites.com'] = 'default'; 
$sites['example1dev.example.com'] = 'sitename1'; 
$sites['example2dev.example.com'] = 'sitename2'; 
$sites['example3dev.example.com'] = 'sitename3';

Test Environment Domains

$sites['exampletest.prod.acquia-sites.com'] = 'default'; 
$sites['example1test.example.com'] = 'sitename1'; 
$sites['example2test.example.com'] = 'sitename2'; 
$sites['example3test.example.com'] = 'sitename3';

Prod Environment Domains

$sites['example.prod.acquia-sites.com'] = 'default'; 
$sites['www.example1.com'] = 'sitename1'; 
$sites['www.example2.com'] = 'sitename2'; 
$sites['www.example3.com'] = 'sitename3';

Did not find what you were looking for?

If this content did not answer your questions, try searching or contacting our support team for further assistance.

Back to Section navigation