I've successfully set up a multisite Drupal installation. I now have:

www.example.com --> main site sub.example.com --> a secondary site

However, I want the users to be shared. I know about shared databases and prefixes, but according to the comments in the settings.php, you can also use the prefixes to access a different database. I'd like to choose that root.

So my main site goes to the primary database, the subdomain goes to the secondary database, except for the users.

This is relevant section of the settings.php of my subdomain:

$databases = array (
    'default' => 
        array (
            'default' => 
                array (
                    'database' => 'secondary_database',
                    'username' => 'username',
                    'password' => 'password',
                    'host' => 'localhost',
                    'port' => '',
                    'driver' => 'mysql',
                    'prefix' => array(
                        'default'   => '',
                        'users'     => 'primary_database.',
                        'sessions'  => 'primary_database.',
                        'role'      => 'primary_database.',
                        'authmap'   => 'primary_database.',

My primary database already has many users, but when I log into my secondary site, I only see my admin user. Also, I cannot log in to my subdomain with any user of my primary database.

So my conclusion is that the subdomain is still using its own database.

Both databases are on the same server and I've given the username/password for the secondary database access to the primary database.

There are also no errors in the log.

Any suggestions on what I'm missing?

1 Answer 1


I would advise to look into the answers of this question. One solution is indeed a specific setup in settings.php, however all your sites need to make use of the same database when using that option. E.g.:

$databases['default']['default'] = array(
  'driver' => '[Your database engine]',
  'database' => '[Your database name]',
  'username' => '[Your username for the access to the database engine]',
  'password' => '[The password for the access to the database]',
  'host' => 'localhost',
  'prefix' => array(
    'default'   => 'main_',
    'users'     => 'shared_',
    'sessions'  => 'shared_',
    'role'      => 'shared_',
    'authmap'   => 'shared_',
  'collation' => 'utf8_general_ci',

The solution above uses the same database for all sites, but different table prefixes. So in the example above most tables will be prefixed with "main_", but the users, sessions, role and authmap tables will be prefixed with "shared_". For your additional sites, you will use a different prefix for 'default' (maybe 'site2_', 'site_3', etc.) but the same 'shared_' prefix.

(all credits to zdecibel & Dalin for the example & explanation above)

Another option is using the Domain Access module, which is developed for this kind of purposes.

  • But in the settings.php file that Drupal provides, it states: You can also use a reference to a schema/database as a prefix. This maybe useful if your Drupal installation exists in a schema that is not the default, or you want to access several databases from the same code base at the same time.
    – Peter
    Feb 9, 2014 at 14:30
  • I edited my answer with a bit more explanation on the configuration sample I used in the answer. I have no experience in sharing databases. Perhaps someone else has and can elaborate? Feb 10, 2014 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.