Community

Drupal 7 and multisite with shared user database - my notes

This has been a long road but I think I finally may have gotten there.

I'm keeping my running notes on my site ( http://bbtvnetwork.com/content/tech-news-setting-multsite ) but I will snap a copy of them here for now.

Comments are appreciated if you notice I missed something that will bite me later.

My goal is to run a main system portal at www.main.com
then run many sub-sites at site1.main.com, site2.main.com etc

I'm running on Amazon AWS instance which is basically a RHEL distro.

Since it probably isn't of much interest for this conversation I will condense the setup without comments.

sudo yum update 
sudo vi /etc/yum.repos.d/epel.repo  <-- Under the section marked [epel], change enabled=0 to enabled=1.
sudo yum install httpd
sudo yum install mysql mysql-server
sudo yum install phpmyadmin
sudo vi /etc/httpd/conf.d/phpMyAdmin.conf <-- dangerous but don't restrict to localhost for now
sudo yum install php php-mysql php-gd php-xml php-mbstring
sudo yum install vsftpd                                         
sudo mkdir /srv/ftp
sudo usermod -d /srv/ftp ftp
sudo vi /etc/vsftpd/vsftpd.conf  <-- secure anonymous
sudo chkconfig --level 2345 mysqld on
sudo service mysqld start
sudo chkconfig --level 2345 httpd on
sudo service httpd start
sudo chkconfig --level 2345 vsftpd on
sudo service vsftpd start
/usr/bin/mysqladmin -u root password 'NewPW'
Virtual Host Stuff http://gotdrupal.com/videos/multisites-vs-multiple-sites
sudo
yum install php-pear
sudo pear channel-discover pear.drush.org
sudo pear install drush/drush
sudo pear upgrade --force Console_Getopt
sudo pear upgrade --force pear
sudo pear upgrade-all
cd /var/www
sudo curl -O http://ftp.drupal.org/files/projects/drupal-7.19.tar.gz
sudo
tar -zxvf drupal-7.19.tar.gz
sudo rmdir html   ←make sure on this!
sudo cp-R drupal-7.19 html
cd html
Browse to http://your.site.com/phpmyadmin --->  to create user/pw and main site database

Create the main site using the following drush commands noting that we're using a database prefix of 'shared_' since this is the base from which others will share their user data.

sudo drush site-install standard --account-name=[drupal_admin_user] --account-pass=[drupal_admin_pw] --db-url=mysql://[db_admin_user]:[db_admin_pw]@localhost/[db_name] --site-name="Text Site Name" --site-mail="info@domain.com"  --db-prefix=shared_

sudo drush dl libraries awssdk amazons3 videojs entity rules ctools views cck token devel jquery_update custom_formatters pathauto zen admin_menu themekey-7.x-2.x-dev simplehtmldom devel_theme captcha-7.x-1.x-dev recaptcha

sudo chown –R apache:apache sites/default/files

Enable desired modules and set up the main site. Create users and enable roles etc.

After the main site settles down and you want to create the second site...

Setup the second site files as

sudo mkdir sites/site2.main.com
sudo mkdir sites/site2.main.com/files
sudo chown –R apache:apache sites/site2.main.com/files
sudo cp sites/default/default.settings.php sites/site2.main.com/settings.php
sudo chown apache:apache sites/site2.main.com/settings.php

Run the install on the second site by going to http://site2.main.com/install.php and continue as normal *except* at the database page, go to advanced and set a unique prefix for all of these table. Something like 'site2_'

Note that we have not yet set up the user database sharing yet. To redirect the tables, edit the settings.php file in the second directory to be:

/*************
*
* Shared user tables:
*   authmap
*   users
*   role
*   role_permissions
*   users_roles
*   sessions
*/
$databases = array (
  'default' =>
  array (
    'default' =>
       array (
         'database' => '[main table name]',
         'username' => '[db_user]',
         'password' => '[db_pw]',
         'host' => 'localhost',
         'port' => '',
         'driver' => 'mysql',
         'prefix' =>
           array (
              'default' => 'site2_',
              'authmap' => 'shared_',
              'users' => 'shared_',
              'role' => 'shared_',
              'role_permissions' => 'shared_',
              'users_roles' => 'shared_',
              'sessions' => 'shared_',
           ),
       ),
  ),
);

Comments

Hmm, reCaptcha seems to be

Hmm, reCaptcha seems to be not working. In single site mode it keeps nearly 100% of bot users out but here I am getting a lot of bot users.

Something about my user tables and reCaptcha is not working.

I'm trying regular captcha now.

BTW, I had both main and site2 modules set the same in the user/captcha settings.

I still develop a multisite

I still develop a multisite with drupal 7. I need to share all users field, so i put some prefix on my settings.php.

<?php
'field_data_field_first_name' => 'shared_', //stored with shared_ prefix
'field_revision_field_first_name' => 'shared_', //stored with shared_ prefix
'field_data_field_last_name' => 'shared_', //stored with shared_ prefix
'field_revision_field_last_name' => 'shared_', //stored with shared_ prefix
'field_data_field_phone_ext' => 'shared_', //stored with shared_ prefix
'field_revision_field_phone_ext' => 'shared_', //stored with shared_ prefix
'field_data_field_business_unit‎' => 'shared_', // -----> PROBLEM did not stored with shared_ prefix
'field_revision_field_business_unit‎' => 'shared_', // -----> PROBLEM did not stored with shared_ prefix
'field_data_field_departement‎' => 'shared_', // -----> PROBLEM did not stored with shared_ prefix
'field_revision_field_departement‎' => 'shared_', //-----> PROBLEM did not stored with shared_ prefix
?>

Why my business unit and departement field did not stored with shared_ prefix ?

nobody click here