Wiki Page: Multisites Using Drupal 7

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

PLEASE MODIFY THIS DOCUMENT with your tips and clues and links and hard-won wisdom.

What Is Multisites?

Multisites is a capability of Drupal to run many web sites out of one installation of Drupal.

That is, if you install Drupal somewhere, you can then place different file directories and settings files for a number of different web sites within the /sites folder.

Because of the way multisites works, you can have different domains and subdomains and paths mapped to different directories within /sites. So, for instance, while Drupal multisites can support two different websites like example.com and anotherexample.net, it can also support different settings and databases for example.com and foobar.example.com.

Drupal 7 adds a relatively easy ability to define multiple databases per site (in parallel, and also as master/slave setups), and also share databases between sites.

As a development convenience, Drupal 7 file allows you to set up domain aliases, as well. This lets you develop a web site locally, as localhost for instance, which will map to one of your multisite directories, such as example.com. This is done using the example.sites.php file. Details below.

One Install To Rule Them All

The philosophy of multisite: Do as little as possible, and let Drupal figure it out.

Do not mess with symbolic links or aliases. Do not add other modules until you're sure you need them. Just get your multisite setup working acceptably first by reading a lot, configuring a little, and assuming Drupal knows what its doing.

How To?

The first rule: Read the code. :-) example.sites.php and default.settings.php tell you a lot, if you just read them.

The coolest addition in D7 is sites.php, which lets you set domain aliases, so that if you come from localhost (under MAMP, for instance), the connection can still be mapped to sites/yourfancysitename.com while you're developing and staging it. You can read it in the API documentation, which is taken directly out of the source file: http://api.drupal.org/api/drupal/sites--example.sites.php/7

The other cool thing is that D7 can let you mix and match databases and prefix much more flexibly than D6. This gets explained in default.settings.php. You can have master and slave DBs, and give different databases different names within Drupal. This is explained here: http://drupal.org/node/310071

An article on some of this: http://www.drupalcoder.com/story/544-drupal-7-multisite-improvement-mult...

The Skeleton of a Drupal 7 multisite guide can be as follows :

  1. Install Drupal 7 the normal way on the first domain.

  2. Make your DNS work for the second site's domain (2ndsite.com) to point to same IP.

  3. Make your Web server work for the second site's domain to point to same directory. (for apache this can be adding the second domain as an alias in the current host or making a new virtual host that has the same document root)

  4. Make a new directory with name equal to the second site's domain in under the sites directory (drupal7/sites/2ndsite.com)

  5. Either :
    5.a. chmod the second site's directory (drupal7/sites/2ndsite.com) to 777 (change permissions so that they can be modified by anyone)
    OR
    5.b. Make a new directory called files (drupal7/sites/2ndsite.com/files) and chmod this new directory to 777.

  6. Copy default.settings.php to the new site's directory as settings.php (drupal7/sites/2ndsite.com/settings.php) and then chmod it to 666

  7. Navigate to the second domain (2ndsite.com) and install Drupal normally.

It can be easily noticed that steps from 5 to 7 are normally done when installing Drupal (like in first step).

For a multisite local installation of Drupal, see Local multi-site installation of Drupal 7 on Linux.

Alternatively steps 7 and further in my situation (@summit):
+++++++
7. Copy example.sites.php to sites.php (keep it withing drupal7/sites) then chmod it to 666
8. Add the bottom op sites.php set up the mapping using the sites array:view source
$sites['secondsite.com'] = 'secondsite.com';
9. Then chmod sites.php it to 666
10.Navigate to the second domain (2ndsite.com) and you will see the first site.
11.Add domain access module and other domain modules: www.drupal.org/project/domain for best multisite handling.
12. All of the sites will want to use the .htaccess file in the main D7 directory. For this reason, the RewriteBase directives in this .htaccess must be commented out:

RewriteBase /drupal

RewriteBase /

Otherwise clean urls will not work.
+++++++

Working with Primary domains and Root subdirectories

If you want to store all Drupal files in a subdirectory on root (public_html) and then point the primary domain to that subdirectory, here's how I did it so that when I visited my site I wouldn't see the subdirectory be part of the URL, and most important, that it will still work with URL aliases and the Multisite structure, e.g.

http://example.com/<subdirectory> // bad

http://example.com // good

  1. I added the following lines on the .htaccess of the root folder (Not the .htaccess of the Drupal directory).

RewriteEngine on
RewriteRule ^(.*)$ http://<domain>/<subdirectory>/$1 [P]

  1. Added the $base_url in the "settings.php" file.

$base_url = 'http://<domain>'; // NO trailing slash!

Transform old separate sites into Multisite

Possible issues
Blank page ›› Flush all caches in your database before import: in drupal interface (admin… or admin menu top left) or empty all caches in phpmyadmin… If not, and if you are using specific themes in sites/yourwebsite.com/themes, you could have blank pages because drupal will search for the template in the wrong file
Missing images ›› need a query "replace" or "update" in your database to replace all src images from sites/DEFAULT/files into sites/YOURSITE.COM/files or use Search and replace module to do it in drupal interface. Do not forget the specific icon in Apparence, nor the blocks and pages that are not "scannarable" as front pages. Flush drupal and firefox caches.
To replace all path occurences from /sites/default/files to /sites/your_sitename/files use this sql query with drush:

drush -l your_sitename.yourdomain -r /your/path/to/drupal_root sql-query "update field_data_body set body_value = replace(body_value, '/sites/default/files/', '/sites/yousitename.yourdomain/files/') where body_value like '%/sites/default/files%';"

use -l to do it only for your sitename only and not for all sites in drupal installation!!
Pay attention to single and double quotes.
Missing attached images ›› change your file system path (in /admin/config/media/file-system): same as above. Flush drupal and firefox caches.

I did not find documentation on how to do this anywhere, so I decided to add it to this Wiki; which is the first place I checked for this solution. Feel free to suggest a better solution or modify this one if needed.

Multisite

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: