Setup of /sites directory for multi-site
Drupal's multi-site hosting capability is built in with any installation. This is great news for users who run numerous web sites from a single hosting account. A single Drupal installation can be used to run multiple domains, which makes it much easier to manage and maintain the code base. Even if you are dealing with only one domain, the multi-site capability may be valuable by providing the ability to run a separate domain or sub-domain for a development version.
This page describes the set-up of the /sites directory for multi-sites.
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 |
The intended best practice configuration is to create a /sites/example.com directory for each domain. It should contain a site-specific settings.php file and /files directory. Configure Drupal site settings to specify 'File System Directory' of 'sites/example.com/files' instead of the default 'files'. It's possible to do this with an existing web site, but moving file uploads around can cause a lot of confusion if there are already URLs pointing to the old locations.
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/tmpIf 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 .htaccess
Once 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.
- All of your custom themes, add-ons, settings, and so on will be in /sites/example.com, /sites/all, or /sites/default.
- /sites/default/settings.php and /files will be used if there is no /sites/example.com directory.
- /sites/all/modules and /themes will be available to all sites.
- 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
To help keep files organized you may choose to use short-cuts to point relevant files and directories that are stored elsewhere in your Drupal installation. These short-cuts (like a desktop "alias") are referred to as "symbolic links" on a Web server. Symbolic links can be used for several purposes:
- 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.
If you are working from the command line on a Linux, Unix or OSX server you can create a symbolic link using the following command:
$ 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:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]If the .htaccess method doesn't work, try this user-contributed code for use in settings.php, instead of .htaccess.
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';
?>
Multisite Files directory issue
I'm using Drupal 6. To implement multisite I parked a secondary domain over the primary domain and so don't need or use symlinks or aliases (which are always an issue on shared hosting). It's all run out of a single database with a prefix for each set of tables. The basic setup was easy. Congratulations Drupal developers.
The issue I faced was the ability to provide separate upload directories for each domain.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]
This Mod Rewrite code sounded about right but I struggled to get it working. I eventually discovered if I accessed the domain without including www. in the URL the Mod Rewrite worked as predicted. With the benefit of hindsight this makes sense as the domain name in the /sites directory doesn't include the www. prefix. So now I have changed the .htaccess in the root directory to rewrite the URL and eliminate the www. prefix. [There was sample code in the supplied .htaccess, so again this was pretty easy.]
The limitation I see with this solution is the need to add a new rewrite condition and rule for each domain hosted with a requirement for an upload directory.
I hope my experience can help someone else struggling with this.
del
nvm
Is default/tmp folder missing from example directory structure?
Excellent resource page, just wondering if there should be a /drupal/sites/default/tmp folder added to the list after the fourth item (/drupal/sites/default/settings.php) in the example ideal directory structure list.
Apologies if this is a dumb suggestion and/or I've posted this suggestion in the wrong place.
.com causes IIS to freak?
I just realized a problem on my server, when I try to access the folder website.com/drupal/sites/website.com/ it gives me this error message:
ou are not authorized to view this page
You do not have permission to view this directory or page due to the access control list (ACL) that is configured for this resource on the Web server.
Please try the following:
* Contact the Web site administrator if you believe you should be able to view this directory or page.
* Click the Refresh button to try again with different credentials.
HTTP Error 401.3 - Unauthorized: Access is denied due to an ACL set on the requested resource.
Internet Information Services (IIS)
Technical Information (for support personnel)
* Go to Microsoft Product Support Services and perform a title search for the words HTTP and 401.
* Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled About Security, Access Control, and About Custom Error Messages.
IIS is trying to serve the .com as the filetype .com which triggers a username/password prompt and then the above error message.
Any ideas on how to make it so drupal can still use the directories w/o ".com" on the end or a way to fix IIS?
Its not folder permission issue, as I can rename the folder to anything not .com and it works (.org, .net, etc) but then drupal breaks for the website...
Hi, I want to install a
Hi,
I want to install a multisite using sub URL for example :
www.example.local -> pointed to drupal core and act as a master drupal site.
www.example.local/site1 -> plan to point in sites/www.example.local.site1 (is this correct?)
www.example.local/site2 -> plan to point in sites/www.example.local.site2 (is this correct?)
in my vhosts entry :
127.0.0.1 www.example.local
in my apache :
<VirtualHost 127.0.0.1>DocumentRoot "d:\www\drupal"
ServerName www.example.local
<Directory "d:\www\drupal">
Options Indexes FollowSymLinks
AllowOverride all
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
Is this correct?
A word to the wise...
... to anyone starting a fresh multisite installation or expanding an existing one: Take advantage of the way Drupal is set up for multi-sites and compartmentalize. If you put modules and themes in the "all" folder, things can get kloodgy and difficult to unwind.