Two Drupal installations with a shared userbase

By fiLi • Jan 20th, 2007 • Category: Drupal

I’ve implemented a  ”two Drupal installations with a shared userbase” setup last week with Drupal 4.7 and to my extreme surprise it worked like a charm and the whole thing took less than 15 minutes.

I have two sites, running on the same server, each on a different database, which I wanted to use the same userbase. If the sites are on the same database with different prefixes then a different method can be applied (using a simple module).

In the settings.php of the site I setup which is connecting to a different site’s user database, I setup the following :

$db_url = ‘mysql://user_name:password@localhost/newdatabasename’;

$db_prefix = array(
‘default’ => ‘newdatabasename.’,
‘bookmarks’ => ‘otherdatabasename.’,
‘buddylist’ => ‘otherdatabasename.’,
‘buddylist_buddy_group’ => ‘otherdatabasename.’,
‘buddylist_groups’ => ‘otherdatabasename.’,
‘location’ => ‘otherdatabasename.’,
‘permission’ => ‘otherdatabasename.’,
‘privatemsg’ => ‘otherdatabasename.’,
‘privatemsg_archive’ => ‘otherdatabasename.’,
‘privatemsg_folder’ => ‘otherdatabasename.’,
’sequences’ => ‘otherdatabasename.’,
’sessions’ => ‘otherdatabasename.’,
‘authmap’ => ‘otherdatabasename.’,
‘userpoints’ => ‘otherdatabasename.’,
‘users’ => ‘otherdatabasename.’,
‘users_roles’ => ‘otherdatabasename.’,
‘profile_fields’ => ‘otherdatabasename.’,
‘profile_values’ => ‘otherdatabasename.’,
);

This shares the basic user tables - authmap, users, users_roles, permissions, sequences, and sessions as well as module specific user related tables -

  • Bookmarks module - bookmarks.
  • Buddylist - buddylist, buddylist_buddy_group, buddylist_groups.
  • Location - location.
  • Privatemsg - privatemsg, privatemsg_archive, privatemsg_folder.
  • Userpoints - userpoints.
  • Profile - profile_fields, profile_values.

If you have two sites, then what you might want to do is:

  • Stop any activity on both sites.
  • Change the settings.php on site1 to point to sharing site2’s DB.
  • Export the shared tables from site1 and import those into site2.
  • Test and make sure everything is running okay and resume activity.

Tagged as:

Leave a Reply