example.sites.php

You are here

  1. 7 sites/example.sites.php
  2. 8 sites/example.sites.php

Configuration file for Drupal's multi-site directory aliasing feature.

This file allows you to define a set of aliases that map hostnames, ports, and pathnames to configuration directories in the sites directory. These aliases are loaded prior to scanning for directories, and they are exempt from the normal discovery rules. See default.settings.php to view how Drupal discovers the configuration directory when no alias is found.

Aliases are useful on development servers, where the domain name may not be the same as the domain of the live server. Since Drupal stores file paths in the database (files, system table, etc.) this will ensure the paths are correct when the site is deployed to a live server.

To use this file, copy and rename it such that its path plus filename is 'sites/sites.php'. If you don't need to use multi-site directory aliasing, then you can safely ignore this file, and Drupal will ignore it too.

Aliases are defined in an associative array named $sites. The array is written in the format: '<port>.<domain>.<path>' => 'directory'. As an example, to map http://www.drupal.org:8080/mysite/test to the configuration directory sites/example.com, the array should be defined as:

$sites = array(
  '8080.www.drupal.org.mysite.test' => 'example.com',
);

The URL, http://www.drupal.org:8080/mysite/test/, could be a symbolic link or an Apache Alias directive that points to the Drupal root containing index.php. An alias could also be created for a subdomain. See the online Drupal installation guide for more information on setting up domains, subdomains, and subdirectories.

The following examples look for a site configuration in sites/example.com:

URL: http://dev.drupal.org
$sites['dev.drupal.org'] = 'example.com';

URL: http://localhost/example
$sites['localhost.example'] = 'example.com';

URL: http://localhost:8080/example
$sites['8080.localhost.example'] = 'example.com';

URL: http://www.drupal.org:8080/mysite/test/
$sites['8080.www.drupal.org.mysite.test'] = 'example.com';

See also

default.settings.php

conf_path()

http://drupal.org/documentation/install/multi-site

File

sites/example.sites.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Configuration file for Drupal's multi-site directory aliasing feature.
  5. *
  6. * This file allows you to define a set of aliases that map hostnames, ports, and
  7. * pathnames to configuration directories in the sites directory. These aliases
  8. * are loaded prior to scanning for directories, and they are exempt from the
  9. * normal discovery rules. See default.settings.php to view how Drupal discovers
  10. * the configuration directory when no alias is found.
  11. *
  12. * Aliases are useful on development servers, where the domain name may not be
  13. * the same as the domain of the live server. Since Drupal stores file paths in
  14. * the database (files, system table, etc.) this will ensure the paths are
  15. * correct when the site is deployed to a live server.
  16. *
  17. * To use this file, copy and rename it such that its path plus filename is
  18. * 'sites/sites.php'. If you don't need to use multi-site directory aliasing,
  19. * then you can safely ignore this file, and Drupal will ignore it too.
  20. *
  21. * Aliases are defined in an associative array named $sites. The array is
  22. * written in the format: '<port>.<domain>.<path>' => 'directory'. As an
  23. * example, to map http://www.drupal.org:8080/mysite/test to the configuration
  24. * directory sites/example.com, the array should be defined as:
  25. * @code
  26. * $sites = array(
  27. * '8080.www.drupal.org.mysite.test' => 'example.com',
  28. * );
  29. * @endcode
  30. * The URL, http://www.drupal.org:8080/mysite/test/, could be a symbolic link or
  31. * an Apache Alias directive that points to the Drupal root containing
  32. * index.php. An alias could also be created for a subdomain. See the
  33. * @link http://drupal.org/documentation/install online Drupal installation guide @endlink
  34. * for more information on setting up domains, subdomains, and subdirectories.
  35. *
  36. * The following examples look for a site configuration in sites/example.com:
  37. * @code
  38. * URL: http://dev.drupal.org
  39. * $sites['dev.drupal.org'] = 'example.com';
  40. *
  41. * URL: http://localhost/example
  42. * $sites['localhost.example'] = 'example.com';
  43. *
  44. * URL: http://localhost:8080/example
  45. * $sites['8080.localhost.example'] = 'example.com';
  46. *
  47. * URL: http://www.drupal.org:8080/mysite/test/
  48. * $sites['8080.www.drupal.org.mysite.test'] = 'example.com';
  49. * @endcode
  50. *
  51. * @see default.settings.php
  52. * @see conf_path()
  53. * @see http://drupal.org/documentation/install/multi-site
  54. */

Comments

First unclear line:
$sites = array( 'devexample.com' => 'example.com', 'localhost.example' => 'example.com', );

Is the key or the value the directory name because they're both at .com in the first key-value pair of the array? In the second key-value pair, is localhost.example supposed to be localhost/example, or is it supposed to be a url, or something else?

Later in the file, we have :
# $sites['devexample.com'] = 'example.com';
# $sites['localhost.example'] = 'example.com';

Does this make the alias example.com for both directories? Why would you give two separate directories the same alias? Is localhost.example a directory name, is it supposed to be localhost/directory, or that a url of some sort?

The key of the array should be your hostname, the value the path.

Example: 2 websites, configured as 2 virtual hosts.
The url's of your (production) websites are
1) http://www.myfirstsite.com
2) http://www.mysecondsite.com

On your production server, you have created the following paths :

./drupal/sites/default // this directory hosts the settings file for your first site
./drupal/sites/mysecondsite.com // directory with the settings for your second site

On your production server, you don't need a sites.php.

But if you want to keep the same file structure on your DEV server (which is a good
idea), you can use the sites.php.

As an example, we define the url's for the DEV websites like:
1) http://www.dev-myfirstsite.com
2) http://www.dev-mysecondsite.com

we keep the same file structure , thus the same paths:

./drupal/sites/default
./drupal/sites/mysecondsite.com

Now you have an issue: as-is, Drupal will link your http://www.dev-mysecondsite.com to the 'default' directory.

That's where the sites.php comes into the game. Set your hostnames in the key, and your paths in the values, and Drupal will handle your url's as required. Your sites.php would look like this :

$sites['www.dev-myfirstsite.com'] = 'default';
$sites['www.dev-mysecondsite.com'] = 'mysecondsite.com';

I have Drupal installed on localhost. localhost points to Drupal root. The folder for my site exists at sites/example.com.

When I put this alias in sites.php, and visit http://localhost, everything works fine:

<?php
$sites
['localhost'] = 'example.com';
?>

But, since I would like to access all my Drupal sites on localhost, what I really want is:

<?php
$sites
['localhost.example'] = 'example.com';
?>

just like example.sites.php says to do. However, when I use that alias (for localhost.example instead of just localhost), http://localhost/example simply takes me to the Drupal install.php page as though the alias was not found

Because the "localhost" alias works, I know that the subfolder for my site exists, the database exists, and everything connects fine. It's only when I change the alias from localhost to localhost.example and view http://localhost/example instead of http://localhost do I have problems.

Does anyone have any idea what might be causing this?

IMHO the value for the settings ('example.com') is misleading. Actually, this is the name of the subdirectory in your sites directory and not a domain name.

So what should work is $sites['example.localhost'] = 'example';.

HTH
Frank

True. However, if you only have one domain name for that site you don't need to use sites.php at all, as simply naming the folder example.com will let Drupal discover it.

The use-case for this file is when you want to make sure that example.org works as well.

So normally you'd have the following setup:

sites/
sites/all/*
sites/default/*
sites/example.com/*
sites/something.net/*

and Drupal would use the appropriate ones for each domain.

However, if you have two different domains that Drupal doesn't recognize as the same (see default.settings.php for explanation of how Drupal discovers site configurations) you need to use sites.php, and in that case you'd already have a folder named example.com and therefor your sites.php would look like the following:

<?php
$sites = array(
  'example.net' => 'example.com',
);

Without this code, example.net would simply use the default configuration found in sites/default/*.

$sites['mysite.com'] = 'default';
$sites['m.mysite.com'] = 'mobile';

mobile/files is a symbolic link to default/files

- theme_style_image return the right URL.
- does not create the images in files/

i do not understand why images are not created for other sites that are not the default one.

I am finding that the drupal will not read 'settings.php' when in a subdirectory referred to via sites.php, eg
The code in sites.php is:
$sites['2012.www.cpddomain.com.test'] => 'test_directory';

When I browse to www.cpddomain.com:2012/test, all I see is a directory listing of whats in /sites/test_directory, which is:
settings.php , default.settings.php and test.php

Whereas if I replace the contents of /test_directory with 'index.html', drupal will now read 'index.html' in that same dir

This is the relevant part of httpd.conf:

DocumentRoot "/var/www/html/drupal-7.21"
ServerName cpddomain.com
# I found you don't need to add an 'alias' line in httpd.conf as long as you add trailing #slash after the url, eg http://www.cpddomain:2012/test/
#Alias /test /var/www/html/drupal-7.21/sites/test_directory

Options Indexes FollowSymLinks MultiViews
AllowOverride none
#AllowOveride all # you cant access the /test link with 'override all'
Order allow,deny
allow from all
AddType application/x-httpd-php .php

HOWEVER, drupal will read 'settings.php' (and I can proceed with a new drupal installation) if I forget the subdirectory thing, ie
$sites['2012.www.cpddomain.com'] => 'test_directory';

Anyway, its not makin' sense to me!
MD

Just a tip here for anyone struggling with this.

You should be pointing any domains/subdirs at the root of the drupal installation NOT at the sites/xxx directory.

If you don't have a "default/settings.php" a good way of getting drush working from the root of your Drupal installation is to add:

$sites['default'] = 'example.com';

to your sites.php

If you don't have a "default/settings.php" a good way of getting drush working from the root of your Drupal installation is to add:

$sites['default'] = 'example.com';

to your sites.php