For this example we have three sites http://www.example.com/master, http://www.example.com/slave1, http://www.example.com/slave2. I want to be able to sign on to one site and to be signed in to all.
Start by setting up the master site as you normally would (if you haven't set up a multisite before this earlier post may help). The only additional thing to do is to set the cookie_domain variable in the sites settings.php:
$cookie_domain = 'master';
Now go ahead and setup slave1. Once again add the cookie_domian (using the same value as the master site) but this time also define the db_prefix array. You use this to tell this site to use the database from the master site for some of the tables. Lets say that the master site uses a database called masterdb. To tell slave1 to use this database for the users table add 'users' => 'masterdb.' to the db_prefix array. The exact list of tables you'll need to add will depend on how much functionality needs to be shared across your sites. Eric's post adds users, sessions and authmap. I've also added filters, filter_formats and role :
$db_prefix = array(
'default' => '',
'access' => 'masterdb.',
'authmap' => 'masterdb.',
'filters' => 'masterdb.',
'filter_formats' => 'masterdb.',
'role' => 'masterdb.',
'sessions' => 'masterdb.',
'users' => 'masterdb.'
);
Now you are ready to install slave1. When that's done you should be able to log out of and into either site and stay logged in across both. Repeat the steps used for slave1 on the slave2 site. That's all there is to it. In essence all that's required is to share some core tables and the cookie domain across all sites. The only problem I struck was if the cookie_domain isn't an actual domain.
1 comment:
Thanks for your post!
I have an Apache-config question, as I'm trying to get Drupal multisite setup.
I've tried to setup my Apache virtual hosts to allow for your sub-folder style of 'master', 'slave1' and 'slave2'. I'm able to setup the 'master' just fine, but when I try to reach 'slave1' to do the initial installation, it says it's not found. I've edited my httpd-vhosts.conf (XAMPP installation) and my Windows "hosts" file.
I know the files are being read properly, because I can change 'localhost' to something like 'blah' and have it work properly, but only for folders that exist (not for a vhost that points to a folder that exists, like 'slave1' would).
Could you provide any help? Thanks again for your informative articles.
Post a Comment