I am trying to setup multisite for Drupal 7, with user logins shared across sites, and separate databases for the shared and the site unique bits. Has anybody successfully done this, and if so, how?

The setup I would like is:
shared data (users, authmap, sessions, role and user_roles tables) - database dbshared
site1 - database dbsite1
site2 - database dbsite2

The following video shows basically how to do it with Drupal 6 (using the $db_prefix variable):,
http://drupalize.me/videos/multisite-architecture-diwd-08

But I am trying to get it working on D7. I have tried it with a settings.php file for site1 like the following:

$databases = array (
  // define my default site1 database
  'default' =>
  array (
    'default' =>
    array (
      'database' => 'dbsite1',
      'username' => 'myuser',
      'password' => 'mypassword',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => array(
        'default'   => '',
        'users'     => 'dbshared.', // try and tell drupal to use dbshared.users for the users table
      )
    ),
  // Now define my shared db
  'dbshared' =>
  array (
    'default' =>
    array (
      'database' => 'dbshared',
      'username' => 'myuser',
      'password' => 'mypassword',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
);

I tested this on my site1 by creating a new user and seeing where the user row entry appeared. Unfortunately it's not using the dbshared database, but rather uses the dbsite1 database.

Do you know what I am doing wrong? Is there other stuff I need to do?

The following post suggests I need to explicitly swap databases, though I note that they do not use the table prefix to try and automate this:
http://drupal.stackexchange.com/questions/31325/how-to-let-drupal-use-tw...

Thanks for your help.

Comments

absoludo’s picture

To setup a multisite in Drupal I would recommend using the Domain Access module.
There you can use the same database and say which user can access which node, etc.

All data in one centralized database and many additional contrib modules to enhance the multisite experience.