With version 5.x, the intended location for all non-core elements of a Drupal installation is in a separate /sites directory inside the Drupal installation.
Directory | Contents |
---|---|
/drupal/sites/all (used by all sites) | /modules /themes |
/drupal/sites/default (used when there is no /sites/example.com directory) | /files settings.php |
/drupal/sites/example1.com | /files /modules /themes /tmp settings.php |
/drupal/sites/example2.com | /files /modules /themes /tmp settings.php |
Domain specific modules and themes should also be placed in /sites/example.com/modules and /sites/example.com/themes respectively.
Contributed modules and additional themes which are for use by all domains in a multi-site installation should be placed in /sites/all/modules and /sites/all/themes. Note that there shouldn't be a /sites/all/files or /sites/all/settings.php.
The /sites/default directory should contain /files and settings.php, for use if the /sites/example.com directory doesn't exist for a domain.
In addition to multiple sites, such as example1.com and example2.com, sub domains are also easily set up. Adding sub3.example2.com and sub3.example2.com/site4, the directory structure for these four sites would be:
/drupal/sites/all/modules
/drupal/sites/all/themes
/drupal/sites/default/files
/drupal/sites/default/settings.php
/drupal/sites/example1.com/files
/drupal/sites/example1.com/modules
/drupal/sites/example1.com/settings.php
/drupal/sites/example1.com/themes
/drupal/sites/example1.com/tmp
/drupal/sites/example2.com/files
/drupal/sites/example2.com/modules
/drupal/sites/example2.com/themes
/drupal/sites/example2.com/tmp
/drupal/sites/example2.com/settings.php
/drupal/sites/sub3.example2.com/files
/drupal/sites/sub3.example2.com/modules
/drupal/sites/sub3.example2.com/settings.php
/drupal/sites/sub3.example2.com/themes
/drupal/sites/sub3.example2.com/tmp
/drupal/sites/sub3.example2.com.site4/files
/drupal/sites/sub3.example2.com.site4/modules
/drupal/sites/sub3.example2.com.site4/settings.php
/drupal/sites/sub3.example2.com.site4/themes
/drupal/sites/sub3.example2.com.site4/tmp
If you wish to point both of them to the same site, use
/drupal/sites/example.com/
as your directory, and uncomment the corresponding option in your .htaccessOnce you've done this, the file structure of your site will be cleanly organized:
- The main Drupal directory will contain only the standard 'core' files.
- Themes and modules that are shared among all sites are properly placed in /sites/all
- Site-specific themes, modules, and files are compartmentalized and properly placed in /sites/example.com, /sites/example1.com, /sites/sub3.example2.com and /sites/sub3.example2.com.site4 .
- /sites/default/settings.php and /sites/default/files will be used if /sites/example.com directory does not exist.
- Backing up the /sites directory and your Drupal database will give you everything you need to restore the site in the event of a crash, or to move to a new server.
- Adding a domain is easy: just copy the /sites/default directory to /sites/example5.com
- Even if using default settings, a good option is to use links from /sites/example.com directory to point to the /sites/default directory. That way, if the settings and /files are ever changed from the default and actually placed in /sites/example.com, their location does not 'move' and no links are broken.
- Links could also be used to point the /sites/default directory to your primary site.
- A /files directory could easily be shared across two domains without being shared across the remaining domains.
- A non-domain-name path for /files can be setup. If it is possible that the domain name might change (say, from a development name), then you can set up a link from /drupal/sites/moniker to /drupal/sites/example.com, where 'moniker' is a short version of the site name that will remain constant even if /example.com changes.
$ ln -s /path/to/actual/file/or/directory name_of_shortcut
Although the /sites/default directory could contain a /modules and /themes directory, these elements should usually be placed in /sites/all or /sites/example.com. Similarly, although contributed modules could be placed in /drupal/modules as was the practice in version 4.7, this is not recommended.
Multi-site directory setup for sub-domains, including non-standard ports, is described in the installation instructions found in INSTALL.txt.
See multidomain for a contributed module that allows spanning one site across multiple domains, so that specific content types appear on specific domains or sub-domains.
Version 4.6 and 4.7: Best practice for multi-site set-up under version 4.6 and 4.7 is similar to 5.x. The primary difference is that there is no /sites/all directory. Instead, /modules and /themes that are available for all domains are kept in /drupal/modules and /drupal/themes.
Files Directory
The following user-submitted code may be useful in redirecting URLs for the /files directory to the /sites/example.com/files directory. The following code is added to the [drupal_root]/files/.htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
# Note: this will redirect to the /sites subfolder which is identical to
# the domain accessed by the browser. If you use partial domain names as
# the /sites subfolder (e.g. /sites/domain.com vs /sites/www.domain.com)
# you will need to modify the Drupal root .htaccess to remove the leading www
# or modify the following to use the protion of %{HTTP_HOST} that mirrors
# your /sites subfolders
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} ^(.*)\/files\/
RewriteCond %1/sites/%{HTTP_HOST}/files -d
# To redirect the URI to the actual location of the file /sites/<domain>/files/<filesname>
# change the [L] to [L,R]
RewriteRule ^(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]
# If the domain does not have a dedicated /sites/<domain>/files folder allow the
# default folder to catch it.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# To redirect the URI to the actual location of the file /sites/default/files/<filename>
# change the [L] to [L,R]
RewriteRule ^(.*)$ /sites/default/files/$1 [L]
</IfModule>
In settings.php, put this code:
<?php
$conf['file_directory_temp'] = 'sites/' .substr(strrchr(dirname(__FILE__), '/'), 1) .'tmp';$conf['file_directory_path'] = 'sites/' .substr(strrchr(dirname(__FILE__), '/'), 1) .'/files';?>