I'm trying to build Drupal multisite with separate DB but shared user, session and separate roles.

I did this in settings.php:

Master/default/parent site:

$databases['default']['default'] = array (
  'database' => 'db_name',
  'username' => 'db_user',
  'password' => 'db_pass',
  'prefix' => 'pre_',
  'host' => '192.168.xxx.yyy',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',

child/other sites:

$databases['default']['default'] = array (
  'database' => 'otherdb',
  'username' => 'otherdb_user',
  'password' => 'otherdb_pass',
  'prefix' => array(
    'default'            => 'otherdb.pre_',
    'sessions'           => 'db_name.pre_',
    'users'              => 'db_name.pre_',
/*  'user__roles'        => 'db_name.pre_', */
    'users_data'         => 'db_name.pre_',
    'user__user_picture' => 'db_name.pre_',
    'users_field_data'   => 'db_name.pre_',
  'host' => '192.168.xxx.yyy',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',

i grant db permission for otherdb_user to access below in 'db_name':

  • 'sessions'
  • 'users'
  • 'user__roles'
  • 'users_data'
  • 'user__user_picture'
  • 'users_field_data

the problems:

but seems like the session didn't really work, expectation: login session should maintain across sites

User roles in child site shows empty (but no error) when I assign role A in parent site while in child site the role is not available, my expectation it should get the role 'authenticated user' by default.

Am I missing any configuration?

any advise? thanks in advance AnD

  • 1
    Don't share tables. I don't know why that's still even supported. It will not work reliably for many reasons. Different sites don't have the same session cookies, there are many caches involved that will not be correctly invalided if you change one site and many more problems. If you want single sign on, use something like drupal.org/project/simplesamlphp_auth
    – Berdir
    Apr 28, 2016 at 21:17
  • Have you managed to get it working at the end? You may need to specify a cookie domain in your settings.php, as we use to do with Drupal 7 (see: $cookie_domain on drupal.org/node/1096962) - that said, I have no clue if it works for D8. @Berdir - can you elaborate a bit? If there are caching issues, maybe they could be addressed, I'll be interested to look into it. Don't get me wrong - I agree with you that proper SSO solution is better. But as Drupal is inherently multi-site capable, it is a bit sad that the D7 "cheap" multi-domain cookie / shared table solution is lost with D8. Ha
    – rcuny
    Mar 2, 2017 at 13:10
  • @Berdir – Seems this still being encouraged at least on docs.acquia.com/acquia-cloud/develop/drupal/multisite/…
    – leymannx
    Mar 1, 2019 at 21:17
  • @leymannx well, tell them :) Note that the documentation is about D7, the only D8 part is about removing that thing at the end, I doubt anyone tested it there because most table names are different
    – Berdir
    Mar 11, 2019 at 12:10


Your Answer

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

Browse other questions tagged or ask your own question.