Ok... The documents suck. I think we all agree. Well, now. They don't actually suck, but there's a missing overview/general introduction. I'm going to try, and explain, as a Drupal newb (Linux since Slackware .89, or some such), but LAMP expert.
First, you need to know that Drupal does way more to help you than you think in making multiple sites work off a single installation. That's part of the problem with the docs. It's assumed you know this stuff. The key bit is that Drupal looks for sub-site subdirectories based on the inbound host/domain name, and uses the appropriate one, if found. You don't have to do anything other than set these things up so they work.
Second, you only need to set up the Apache virtual hosts to point at the Drupal installation we're talking about. Read the Apache docs on the VirtualHost, and ServerAlias directives. You may have to read up on DNS configurations to get your domain names to point at the proper IP. 99.9999999% of the time, when you register the domain name, you can take care of these both. In any case, it's probably going to be your service provider in a commercial environment, and your systems administrator in other environments. If you're administering your own box, or test box, like me, you may have some reading to do.
Let's assume you have Drupal working properly on an Apache site with a domain name of example.com. You'd better get this far before trying to get the multi-site thing going.
Third, you need to set up Drupal to handle these virtual web sites:
======================================
Step One: In the Drupal 'sites' directory create a subdirectory with a name identical to each of the host/domain names your Apache server will resolve to, other than the main site, example.com. If you set it up to answer example.com, bingo.example.com, and bango.example.com, you need subdirectories named bingo.example.com, and bango.example.com. At this point, if you try to access bingo.example.com, you'll get the original Drupal installation.
Step Two: In the sites directory you found a subdirectory named 'default.' Believe it, or not, this is the configuration for the default site, example.com. In that directory there's a file, settings.php, which you already had to adjust for your database. Copy that file to each of your new subdirectories. This gives you a setup where the sub-sites all work off the same code, same database, and same tables. Since I wanted a separate configuration for each sub-site, I need to use either a separate database for each one, or table prefixes. Since the provider I intend to use charges by the database, I'm going to use table prefixes. In the file, settings.php, there's a line containing $db_prefix = '';. All you have to do is insert something inside the single quotes. I used the domain, or host names, just to be pedantic. So I'd have two settings.php files, one with $db_prefix = 'bingo_';, and the other with $db_prefix = 'bango_';. If you try it now you get a wonderful page of MySQL/PHP errors, since the tables with the prefixes don't exist, so next...
NOTE: I put an underscore after the prefix. It's purely arbitrary, but it makes the table names easier to read. You get things like bingo_system, and bingo_user, instead of bingosystem, and bingouser.
Step Three: You have to actually create the tables in the database. I found a node with a snippet of sed script. Don't use it. It doesn't work on the current mysql files, and neither does the script referenced in the docs. Ok... I use MySQL, so I'm using the file, database.4.1.mysql. I recommend making a copy for each of your installations. I would end up with bingo.mysql, and bango.mysql. Now you have to edit these files, and change all table references, so the table names have the appropriate prefixes. These will be 'CREATE TABLE', and 'INSERT INTO' SQL statements. I just did this on my (gasp) Windows box using an appropriate text editor, so...
In the file bingo.mysql I searched for all instances of 'CREATE TABLE ' (note the space at the end), and replaced each one with 'CREATE TABLE bingo_' (note the underscore). The 'bingo_' string is the exact string I set as the prefix in '..sites/bingo.example.com/settings.php' And you do likewise for each of the other sub-sites you want to set up.
Summary to do one sub-site using table prefixes:
- Get the DNS, and Apache to resolve, and answer, the host/domain you want from the original Drupal install
- Create a sub-directory of Drupal's sites directory with a name equal to the host/domain name as in 1
- Copy the ..sites/default/settings.php to the sub-directory created in 2
- Change the settings.php file from 3, so the prefix is unique
- Duplicate the tables from the original Drupal database, but with the unique prefix prepended to their names
Comments
You are an amazing,
You are an amazing, wonderful person! Thank you for this post!
I'm forwarding it to the doc list. :)
Anisa.
-----------------------------------------------------------
Kindness builds stronger bonds than necessity.
www.animecards.org - 18,000 card scans and counting!
-----------------------------------------------------------
where were you all this weekend?? :D thanks!
wow, although this post is 1.5 years old, this was the best one i found!
btw, i'm still crying of happiness that i found this post and of sadness by reading step 3.
Thanks!
what about if you use separate databases?
At my host, I can have unlimited databases, so doesn't it make sense to limit database size (thus increasing speed of access, hopefully) by using separate databases?
If that's the case, then how would this setup differ? Would I just copy the original database into the database(s) for the sub-site(s)?
I mainly want to have sub-sites for theme demos; it doesn't really have to be a fully functional site, so maybe the above isn't really a consideration? I tried to use the Virtual Sites module but apparently it doesn't work, since all I can get out of it is "Access Denied."
CAn this be done now
I dont know if you are still interested in this.Read your article...it seems to have worked well for rivena...
I would like to have a site with different content say videos,imagesand groups on three different subdomains and the userlist common for all the subdoamins and the main domain.Is this achievable. how do we modify this for Drupal 6.2 and also as my host provides unltd. databases creating seperate databases for each subdomain?
I'm Gratified
I'm gratified this is helping someone. Thanks for the kind words.
The issue of separate databases is to separate the data, including the login, and password information, for each domain/sub-domain, or whatever setup you're running. That is, you may have different people logging in to each setup, so you want entirely different tables. You may have different sections of a site, with different themes, but there's only one set of users. In that case, you'd want to share the login/password tables, but he others would have separate prefixes.
BTW - I'm not a MySQL specialist, but if you're running a single server, the issue of speed is about queries, not tables, although the amount of data in the database obviously impacts performance. You're not going to change the number of queries by amalgamating the tables, or combining them. At least, not by much. The authentication issue is handled by the browser cookie authentication methods after the initial login, so those tables are only used for the login process.
My general theory is to always use the default for everything, as it's easier to recover from disaster, and hacks or mods have a maintenance cost. Personally, if the site was for demo purposes, and there were no real per-user security login issues, I'd just let every sub-site have its own set of tables. As you read, combining them is a bit of a fiddle. Why do it, if you don't have to?
As to having different sub-domains with different content using a single set of authentication tables, please reread the article. That is the gist of the entire thing. If you follow the recipe, that's what you end up with.
Thanks again for the nice words.
Carey
====================================
I'm willing to put up with you, if you're willing to put up with me.
THANKS!!!
This should definately be part of the handbook. Much clearer! BIG THANKS!!
Rosamunda
Buenos Aires | Argentina
www.ligadelconsorcista.org
still missing something
There's still something missing -- what about the installation of Drupal itself? I made the dir inside /sites/ (crypticsites.net) -- I already have a dir in my root called crypticsites.net which is where the domain actually points -- where do I install the Drupal program for the 2nd site? In the dir where the domain actually points ( /crypticsites.net/ ), or in the dir I just made, which is crypticsites.com/sites/crypticsites.net ?
I guess I'm going to use the table prefix method, so that login info can be shared -- but I still don't really get this. If there is a new table, with a prefix, for login info, then how is it shared? Isn't that new table of login info independent of the old table of login info?
..scratching head
(and BTW, thank you very much for still being on top of this thread -- I was afraid it had been orphaned, and you seem to be one of the VERY few folks around still paying any attention at all to this multisite issue)
Subscribing
Subscribing