I have made a Drupal 7 multi-site with 3 sites. Each site is running of the same Drupal install and has a separate database.
The database names are myhost_site1
, myhost_site2
and myhost_site 3
. (My hosting provider puts in the myhost_
automatically).
I need the 3 sites to share the users and user roles. I have read various tutorials and these are the steps I have followed:
1. Created a new database called myhost_users
.
2. Copied the following tables from myhost_site1
TO myhost_users
:
users
, user_roles
, authmap
and sessions
3. Given the database users for each of 3 main databases access to myhost_users
.
4. Open the settings.php for each site and insert the following code (replacing the existing $databse definition):
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'NAME OF DATABASE',
'username' => 'DATABASE USER',
'password' => 'DATABASE PASSWORD',
'host' => 'localhost',
'prefix' => array(
'default' => 'NAME OF DATABASE',
'users' => 'myhost_users',
'sessions' => 'myhost_users',
'role' => 'myhost_users',
'authmap' => 'myhost_users',
),
'collation' => 'utf8_general_ci',
);
5. When I go to my site, I get the following error message:
Uncaught exception thrown in session handler. PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table
6. For the code posted in (4) I have tried using an underscore suffix for the database names (e.g, myhost_users_
), but I still get an error message.
What am I doing wrong. Do I need any settings in "sites/sites.php"?
I would be open to using a module to do this. Bakery is no good as it doesn't share user roles. Account Sync does, but it doesn't seem to work. CAS requires phpCAS which I do not have access to.
Comments
#metoo
Hi,
how do you solved this issue?
To use prefix pointing to database it needs a '.'
at the end. For D7 the per-table prefix should be 'database.'. That also works for D8, but is deprecated. To be removed in D9.
Because of the deprecation advise against using it. Suggest to investigate for alternatives. Those deprecating claim that they exist.