Hello,

Could somebody please post simple step-by-step instructions for using a single Drupal 6 codebase for multiple sites? It would also be nice to have the option to use a different database for each site. Please explain how to do this with with a typical high-featured shared cPanel host and add-on domains.

I gather from searching these forums that the old Drupal 5 multisite instructions are no longer applicable to Drupal 6. I have found some bug reports and confusing posts that don't clarify if multisite configs even work on Drupal 6.

Thanks for the help!

Comments

WorldFallz’s picture

AFAIK, the multisite setup of D6 is no different than D5-- when I setup my D6 dev site I didn't have to do anything different. The Multisite with drupal for dummies node should still be applicable. The main points are 1) you have to setup the domain to point to the root drupal install (not directly to the subsite) and 2) the subsites themselves are created via subdirectories off of /sites in the main drupal install.

Point 1 is the most confusing/challenging as there are several ways of accomplishing that. For shared hosting accounts, I don't believe you can use the VirtualHosts apache directive which I find to be the easiest way. I think most people end up using symbolic links for that. All of this is described in detail at the link above.

rahim123’s picture

The main points are 1) you have to setup the domain to point to the root drupal install (not directly to the subsite)

Thanks, this is the key I think.

ferdinand.soethe’s picture

Thanks, that first point saved my day. I keep forgetting that each and every time :-)

I found a second stepping stone in the the fact that default.settings.php needs to be copied AND RENAMED to settings.php in the new subsite directory for the installer to work properly. Once you have done that you can point your browser to the new domain and setup will start just like in a completely new site, thus allowing you to select the database and table prefix independent from the base installation.

Ferdinand

rahim123’s picture

The problem with the instructions at http://drupal.org/node/107347 is that it appears he is setting up a parked domain (i.e. domain1.com and domain2.com are the same site with the same content.) I want to set up a multiple independent domains using one Drupal 6 codebase but a separate DB for each domain. Can anybody post instructions here?

Thanks!

WorldFallz’s picture

The fact that it's parked has nothing to do with whether or not the databases are separate. I'm no DNS wiz, but I'm not sure how you could have multiple top level domains pointing to the same code base without using parked domains.

Let me see if I can simplify this a bit:

  1. install drupal as normal for the first top level site (let's say www.drupal.com), dont use fantastico. install it manually.
  2. create a new database for the subsite and either create a new user for it or use the same user you created for the original install (i use the same user and it's never been a problem) and grant this user access to the database based on the GRANT code in the INSTALL.mysql.txt file in the root directory of your base drupal install. I use phpmyadmin interface link from cpanel for this.
  3. copy the /sites/default directory and rename it after the domain name of your subsite (let's say www.drupal2.com) which is parked at your host.
  4. edit the /sites/www.drupal2.com/settings.php file and change the $db_url line to reflect the new database you created in step 2 above.
  5. this is where it gets fuzzy: you need to setup apache to redirect the top level domain www.drupal2.com to the root of the base drupal install. There are multiple ways to do this. I use a VirtualHosts directive which you won't be able to do in a shared host account AFAIK. I believe the way most people do this on shared hosting accounts is through a symbolic link. You'll have to refer to the link I provided above for that as I have no clue. But as I mentioned above, the important point here is to point to the base drupal directory and not the subdirectory for the subsite.
  6. navigate to www.drupal2.com and run through the install again. After the install is completed, you will have 2 sites using the same code base but different databases.
  7. rinse and repeat for each additional subsite off the same core code base you want.

Then, when you want to add contributed modules / themes to ALL your drupal sites, you put them in /sites/all/modules and /sites/all/themes of your root drupal install respectively. You'll still have to enable them individually (each subsite is using it's own database), but they will use the same code.

To install modules/themes only to a subsite, install it in a module/theme subdirectory off the subsite. In our example case, you would install to /sites/www.drupal2.com/modules or /sites/www.drupal2.com/themes. Only the subsite will see the modules / themes installed there.

Does that help at all? It's WAY more complicated to explain than it is to do. Once you've got it working, it makes sense and is easy do.

rahim123’s picture

Yes, that does make sense, thanks! A few questions and comments....

5. My host's version of cPanel allows me to set the root of all my add-on domains. So it seems that this would be easy enough, I would simply add www.drupal2.com and set its root to be /public_html where I already have Drupal installed for www.drupal.com.

6. Doesn't install.php normally get deleted? Or should it be deleted normally for security reasons? Hmmm, I now see in my own installation that install.php is present, and when I try to run it, it says I can't install because the DB is not empty. But apparently if I change the DB settings in settings.php in my new site directory and the DB is blank it will allow me to proceed?

Thanks again, I'll let you know when I get around to trying this out.

WorldFallz’s picture

regarding #5: can't hurt to try it. If it seems like the site is constantly being directed to the home page, then it's not working. But it may very well be they provide this functionality through cpanel.

regarding #6: drupal doesn't delete the install.php but I believe I've seen threads that recommend it be deleted manually after installation. I guess just don't delete it until all your sites/subsites are installed.

you're welcome 8-)

8w_gremlin’s picture

I've done exactly what you posted here, and all seems to be working fine, except that I have no content types!

any ideas, I'm using 6.x

webmanoffesto’s picture

Does this apply for working with a subdomain too?

I'm trying to create a drupal multisite
My main drupal site is www.mainwebsite.com/drupal
and
Now as part of my Multisite effort I created the subdomain
esni.mainwebsite.com

I used CPanel to create the subdomain, I created the database, assigned a user to the database, I edited the settings.php file. But now I'm stuck here.

you need to setup apache to redirect the top level domain www.drupal2.com to the root of the base drupal install.

I've never worked with Apache before.

Can you explain better how to do this.

WorldFallz’s picture

A the rest of the quoted paragraph explains, it will all depend on your host configuration. Without knowing more, it's impossible to say.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

bazzly’s picture

I have a few questions (As you can see I have posed the same thing all over)

I have Installed drupal with no problem
I have created a new database for the sub site
I have copy the /sites/default directory and rename it after the domain name of my subsite (www.test1.test.com)
I edited the /sites/subsite/settings.php file and change the $db_url line to reflect the new database

For this part.
this is where it gets fuzzy: you need to setup apache to redirect the top level domain www.drupal2.com to the root of the base drupal install. There are multiple ways to do this. I use a VirtualHosts directive which you won't be able to do in a shared host account AFAIK. I believe the way most people do this on shared hosting accounts is through a symbolic link. You'll have to refer to the link I provided above for that as I have no clue. But as I mentioned above, the important point here is to point to the base drupal directory and not the subdirectory for the subsite.

I created a symlink
cd to /var/www/drupal/
sudo ln -s /var/www/drupal/sites/www.test1.test.com
I'm running this on loaclhost, so that could be the problem? If I go to www.test1.test.com I get "Firefox cant find the server at www.test1.test.com"
Any ideas?

WorldFallz’s picture

www.test1.test.com is probably incorrect.

If your main site is "www.test.com" and you created a subdomain of 'test1' for your subsite, then the uri should be 'test1.test.com'.

The first thing you need to do, before attempting anything with drupal, is place a little 'index.html' file in the subdirectory of the subsite (you can use put something like <b>Hello, World</b> in it) and verify it works with a browser pointed at the proper URL. That will be what you name the subdirectory in the /sites folder.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

bazzly’s picture

ok starting over..... and writing everything I do

So I'm doing all this on localhost. And my folders are
/var/www/drupal Main site (localhost)
/var/www/drupal/sites/drupal2.localhost (sub site)

I copied the directory "default" from /var/www/drupal/sites and re-named it to drupal2.localhost and placed it in /var/www/drupal/sites/drupal2.localhost

I created a new database called drupal2
change the settings.php to added $db_url = 'mysqli://user:password@localhost/drupal2

Next I created a symlink
cd /var/www/drupal
sudo ln -s /var/www/drupal/sites/drupal2

I edit my host file /etc/host
127.0.0.1 drupal.localhost drupal2.localhost

Created virtual host/ vhost_alias

DocumentRoot /var/www/dupal/drupal2.localhost
ServerName drupal2.localhost
ServerAlias www.drupal2.localhost

When I now go to http:drupal2.localhost I get a page full or Warnings. Such as
Warning: Table 'drupal2.access' doesn't exist query: SELECT 1 FROM access WHERE type = 'host' AND LOWER('127.0.0.1') LIKE LOWER(mask) AND status = 0 LIMIT 0, 1 in /var/www/drupal/includes/database.mysqli.inc on line 128

Warning: Table 'drupal2.users' doesn't exist query: SELECT u.*, s.* FROM users u INNER JOIN sessions s ON u.uid = s.uid WHERE s.sid = '781ab020e8d4396ec9d54f3035b12a44' in /var/www/drupal/includes/database.mysqli.inc on line 128

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/drupal/includes/database.mysqli.inc:128) in /var/www/drupal/includes/bootstrap.inc on line 1019

And more..

So am I suppose to use the same database? shouldnt an installer start? Do I need to add more to the drupal2.localhost directory to get the installer to work.

If I put a new settings.php in there and goto http://drupal2.localhost, it forwards me to http://drupal2.localhost/install.php and firefox gives en error Redirect loop. "Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

I feel like I'm so close....

One of the other things I tried is using the settings.php from the main site and and going to http://drupal2.localhost and it gives me the main web site, but a little different. If I logon to one of the two sites, the logon does not carry over to the other.
For example: I log on to drupal.localhost and then go to drupal2.localhost I have to re log on. However If I post something on drupal.localhost it will also show up on drupal2.localhost, and the other way around.

Is this the way its suppose to work?
Advice?
Thanks

Sorry for being a nuisance...

bazzly’s picture

I just about have it. Got it!!! The install file was missing from the drupal directory. This is what helped me
http://drupal.org/node/201673

So when I goto http://drupal2.localhost/install.php the install runs....however when I have my settings.php with the following
$db_prefix = array(
'default' => 'drup2_',
'authmap' => '',
'profile_fields' => '',
'profile_values' => '',
'role' => '',
'sessions' => '',
'users' => '',
'users_roles' => '',
);

it stays on install site and never goes to finish.

If I use the default settings.php without what I posted above everything works fine.

I would like to be able to share users across sites. Am I going to have to try to edit the tables manually?

Update: It now works....didnt do anything other than delete both databases, re-import the one, and ran the installer. It now works....I must say it was fun ripping my hair out, but hey....I learned a lot!

Now I just need to find out how to share users across both sites, and automatically logon to a site once loged on to the other.

WorldFallz’s picture

You're not being a nuisance. Its just there's probably a dozen different ways to do this with many different variables depending on your environment.

The only thing that jumps out at me is your virtual host setup-- the subsite should point to the same document root as the original site, not it's own. And no, you don't have to use the same database. And yes, if configured properly, when you visit subsite.localhost the installer process should kick off again for the additional site.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

bazzly’s picture

Thanks for the info...A bit confused though...I tried it and it works...
so this
DocumentRoot /var/www/dupal/drupal2.localhost
ServerName drupal2.localhost
ServerAlias www.drupal2.localhost

I changed to this
DocumentRoot /var/www/dupal/
ServerName drupal2.localhost
ServerAlias www.drupal2.localhost

and the installer works, but I'm a bit confused as to why. ....Oh...because the name is tied to it......?
Thank you very much!!!!

WorldFallz’s picture

Because with a multisite the main drupal installationl takes care of the redirection for the subsites.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

gavjof’s picture

Thanks for providing clear instructions for mutli-site setup. I've only just needed to attempt this and it worked a treat for my host.

I'm with a large UK host using a shared hosting environment and they provide an option called Domain Mappings where you can have domain1.com and domain2.com run using the same web hosting account. Have just tested using Drupal 7 and it looks to be good.

rahim123’s picture

Hello again,

Very nice work WorldFallz! I finally got around to trying this method, and it works flawlessly. This topic should be listed in the handbook, I never would have figured it out otherwise.

Regards.

WorldFallz’s picture

That's great-- happy I could help. And it is on my list of things to write up for a handbook page, but I'm really anal retentive when it comes to documentation. It's one thing to stream-of-conscienceness it out in a forum thread, but for a Documentation book page I'd like to have it clear, complete, and with some key screenshots. I'm about 1/2 way there... lol. Thanks for posting back that it worked.

=============
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.

mErilainen’s picture

Is it possible to have two installations of Drupal in same database with different prefixes? I'm wishing to share the user and role tables, but have everything else different for the subsites.

WorldFallz’s picture

I've not tried it yet, but Multi-Site, Single Codebase, Shared Database, Shared Sign-on 5.x may be of use.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

fereira’s picture

Take this advice with a grain of salt as I'm a fairly new Drupal user.

You might take a look at the LDAP module (and possibly the CAS module). Once the LDAP (or Active Directory) is set up multiple sites could authenticate and obtain it's roles from the same directory.

charisjane’s picture

These instructions were brilliantly helpful.

I am now doing the dance of joy! - but only after I figured out a step that I was missing that may very well be obvious. ...but I'm very, very new to drupal so...

After going through all the above steps I was getting a load of database table errors "db_name.access' doesn't exist......" etc, etc.

All I need to do to resolve this was run the install, "www.drupal2site.com/install.php" :-)

Ta, ever so muchly for the valuable comments left on this site.

Psunshine’s picture

Excellent. Thanks. Love you :)

Psunshine’s picture

Hi,

I have a small problem with the multisite explained above. Basically I can be logged in at www.example.com but logged out at http://example.com. This is happening on both my main install and secondary one. Any ideas on how to fix?

Thx

fereira’s picture

I understand how multiple sites, and multiple domains can be set up and plan on doing it soon for a couple of sites I am working on. I have a couple of issues though.

I understand symbolic links quite well (as I've been working with unix since 1984) but I do almost all my development on a windows machine, so symbolic links are not an option. I also use multiple hosting environments for my drupal instances, typically one on my development machine (a laptop), and one or more production machines (typically a linux box). As I may be working on more than one site at a time I want to set up my development machine such that it has multiple subsites, which means I need to get multiple domains registered. However, the production machines are separate servers, thus a different "site name" would need to be used (because the domain name is associated with just one machine).

I have set up a drupal development environment that uses a build tool (Jakarta Ant) which allows me to deploy code (primarily themes and modules) into a running instance of Drupal from a build directory. The build directory is managed in a subversion repository. Essentially, I work on the code on my dev machine, test it on a local instance, then commit it to the repository. Then I go to the production machine, check out the updated code and deploy it to the production drupal instance. By changing a single property in a properties file I can tell it to deploy to a different subsite directory on each of the machines.

My question is, is there anything in the subsite directory that cares what the subsite directory is called? In other words, on my dev machine the code would deploy to $drupal_home/sites/test1.mydomain.org and on the production machine it would deploy to $drupal_home/sites/projectname.mydomain.org. I realize that themes can be configured to display the "site name" but other than the text difference does anyone forsee any gotchas?

mErilainen’s picture

You are using also SVN with Drupal.
I have a simple question: Is there any easy way to get the settings for a site which is configured and apply those settings for another installation? I have SVN repository ready, but I haven't used it yet as I'm waiting for Panels, Views, OG and OG Blueprints to update for D6. Meanwhile I have been trying out things with D5.

There should be some way to do these things on a new installation without doing everything manually again for each new setup. I guess installation profiles would match my demands, but I didn't find much information about them.

rsanan-1’s picture

I tried to do a Multi-site Drupal setup 6.3 on a red had enterprise version based on the method mentioned here http://justinhileman.info/blog/2007/06/a-more-secure-drupal-multisite-in...

Has any one here tried this - with any version of drupal...

Any recommendations - does it work??

UPDATE:
I was able to install the multi-site drupal setup successfully today. Will blog my experiences

brainajw’s picture

I have successfully installed a multisite, only issue I am having (maybe its not) is i want to log into the main site (drupal6) and when i go to my multsite (sitetwo.com) i want to still be logged in.

$db_url = 'mysql://UN:PW@localhost/drupal6';
$db_prefix = array(
'default' => 'drupal6_', should this be called main instead?
'users' => 'shared_',
'sessions' => 'shared_',
'role' => 'shared_',
'authmap' => 'shared_',
'sequences' => 'shared_',
);

$db_url = 'mysql://UN:PW@localhost/drupal6';
$db_prefix = array(
'default' => 'sitetwo_',
'users' => 'shared_',
'sessions' => 'shared_',
'role' => 'shared_',
'authmap' => 'shared_',
'sequences' => 'shared_',

);

I've followed several links and documents for install and each get you halfway there, yet errors always persist from it and a solution is found elsewhere.

Does anyone know if the multisites are able to cross logged, i know because of the last security flaw i feel this is not possible anymore for cross scrippting.

If this isn't possible, i'm thinking about creating a full manual with everything I've done to successfully create multsites. This will take some time as I'm interning right now and working a site job as the intern is unpaid.

Thanks

drupy_78’s picture

Hello all, I'm going mad trying to configure a multisite installation locally on my Fedora 18 using LAMP and Drupal v6.
Already successfully installed Master instance reachble from http://localhost URL.
Already created new vhost and new database for the slave instance called slave1 using subdirectory and able to access from http://localhost/slave1 URL, but once created the symlink on master instance root directory, when I point to the URL http://localhost/slave1 Drupal redirect me to Master instance instead of proposing new installation process
Already modified settings.php with the correct db details.

/var/www/html is the Master DocumentRoot ("Alias /slave1 /var/www/html" in http.conf file points to slave instance)
/var/www/html/sites/slave1 is the Slave1 DocumentRoot

Anyone can help?