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.
- 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
To help keep files organized you may choose to use shortcuts 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.
Not clear how to use this
Thankx rebafc for your code and thoughts!
I used your code and it sort of works.
All requests to http://dev-site.intranet.lan/files/filename.jpg resolve to http://dev-site.intranet.lan/sites/dev-site.intranet.lan/files/filename.jpg
So far this is great!
But how can I get Drupal to call the files using the shorter URL?
So a sourceview of my page doesn't give away the sites/sitename/files directories?
Baris Wanschers (@BarisW)
Front-end Drupal developer
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...
If you are working from the
Fine. And what about Windows?
I tried with the usual windows shortcuts, but this didn't do the trick...
The use case:
- on the web server I have a multi-site setup with [drupal-root]/sites/site1.mydomain.com, [drupal-root]/sites/site2.mydomain.com, etc, for different subdomains.
- on my localhost I want to mirror this drupal installation, but I would like to use different domains, such as "site1.localhost" and "site2.localhost".
- later I want to deploy a production version with dedicated domains, such as site1.com, site2.com, site3.com. I do not want to rename the subdirectories in [drupal-root]/sites.
symlinks on windows - junction utility
I found a solution:
On Windows XP you can use the Windows junction utility, see http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx
Somewhere I read that Windows Vista or Windows 7 do support symlinks, so I guess you don't need the junction utility there.
symlinks on windows
The Junction utility is an excellent utility and I have used it to reduce much duplicity for both web and ftp services running on W2K and XP.
donquixote is correct Windows Vista does support symlinks using the mklink from command prompt, see http://techblissonline.com/ntfs-symbolic-link-or-symlink-in-windows-vist....
I have not as yet used Windows 7 it apparently also supports the mklink command, see http://social.technet.microsoft.com/Forums/en-US/w7itpronetworking/threa....
I guess you can NOT copy the
I guess you can NOT copy the Windows symlinks to a Linux server via FTP - am I correct?
Please help with multi-site
Thank you for this valuable resource. However I have an issue :
I had one site already set-up (with settings.php in the default dir).
I wanted to add another site with a new domain. I created the newdomain.com directory in /sites. Write a settings.php with the new database info in it.
However when i enter http://www.newdomain.com/install.php , Drupal says :
======================
Drupal already installed
To start over, you must empty your existing database.
To install to a different database, edit the appropriate settings.php file in the sites folder.
To upgrade an existing installation, proceed to the update script.
View your existing site.
======================
It seems that Drupal is not looking in the newdomain directory but uses the default one.
Any help really appreciated. I am not a tech guy but I love Drupal and would like to use it for 2 sites
Best regards,
Christopher
ps: if I remove the default/settings.php, Drupal raises an error (I don't understand this, it seems that Drupal is *not* looking in the subdirectory newdomain.com for the settings.php
same problem with default/settings.php
I'm having the same issue--Drupal is not looking at the settings.php file in my sites/example.com directory, instead it's taking the default/settings.php directives.
I have the site set up via sym-links from the root webserver directory--the directory structure is like this:
test/:
total 48
-rw-r--r-- 1 user www 57 Dec 9 11:15 xmlrpc.php
-rw-r--r-- 1 user www 56 Dec 9 11:15 index.php
-rw-r--r-- 1 user www 57 Dec 9 11:15 update.php
-rw-r----- 1 user www 1590 Dec 9 11:15 robots.txt
-rw-r--r-- 1 user www 58 Dec 9 11:15 install.php
-rw-r--r-- 1 user www 55 Dec 9 11:15 cron.php
lrwxr-xr-x 1 user www 18 Dec 9 11:17 modules@ -> ../drupal/modules/
lrwxr-xr-x 1 user www 17 Dec 9 11:18 themes@ -> ../drupal/themes/
lrwxr-xr-x 1 user www 15 Dec 9 11:18 misc@ -> ../drupal/misc/
drwxr-xr-x 3 user www 512 Dec 9 13:06 sites/
-rwxr-xr-x 1 user www 9478 Dec 9 13:17 settings.php*
Solution
Just found solution here:
http://geekglue.blogspot.com/2007/09/drupal-multisite-setup.html
Since I'm using a subdirectory structure, i.e., 'mysite.org/drupaltest', 'mysite.org/drupaltest2', I just created the directories in the core drupal installation (drupal/sites) with the directory names, 'drupaltest' and 'drupaltest2'. What I needed to do was name the directories with the complete URL, subsituting a '.' for the '/'. So the sites subdirectory is name 'mysite.org.drupaltest', rather than just 'drupaltest'
It Seems work !!
I just follow your advise and it work.
But I still have a little problem with front page.
I'm use panels on my default sites http://example.com, and use path /front as my front page.
After multi site installation finished on my multi site http://example.com/site-1 and access it, i got a front page from http://example.com. (from http://example.com/front)
But if I direct access http://example.com/site-1/node, i got a correct's page for it.
I want if I access http://example.com/site-1 so I get http://example.com/site-1 frontpage not http://example.com/ front page
Plz help me how it happend and how to fix it
Thx
anjjriit
Early on in the setup
Early on in the setup instructions above the following statement is made (first paragraph after Directory/Contents table) "Configure Drupal site settings to specify 'File System Directory' of 'sites/example.com/files' instead of the default 'files'."
What exactly needs to be done here? I looked in the settings.php document and there is nothing obvious in there that contains any such settings for the "File System Directory".
Thanks.
It seems work !!
I just follow your advise and it work.
But I still have a little problem with front page.
I'm use panels on my default sites http://example.com, and use path /front as my front page.
After multi site installation finished on my multi site http://example.com/site-1 and access it, i got a front page from http://example.com. (from http://example.com/front)
But if I direct access http://example.com/site-1/node, i got a correct's page for it.
I want if I access http://example.com/site-1 so I get http://example.com/site-1 frontpage not http://example.com/ front page
Plz help me how it happend and how to fix it
Thx
anjjriit