0

I have a Drupal 7 Multisite Environment with sub-directories.

(E.g):

  • mainsite.com
  • mainsite.com/multisite1
  • mainsite.com/multisite2
  • mainsite.com/multisite3
  • etc.

Each website has its own Database and all are on the same Database Server

I recently configured the multisites to have a Shared User table along with a few shared custom User fields and that aspect works.

However, I am now unable to use Drush within the Multiste directories.

Previously, I would CD into the directory and be able to run Drush commands for that specific multisite like this:

cd /var/www/mainsite.com/sites/multisite1
drush cc all

Now it tells me that "No Drupal site found".

When I comment out the prefix portion of my settings.php file, Drush works again.

How can I make Drush work for these sites?

Below is what my settings.php file looks like:

$databases['default']['default'] = array(
  'driver' => 'mysql',
  'database' => '[Multisite DB]',
  'username' => '[Database Username]',
  'password' => '[Database Password]',
  'host' => '[DB Server IP]',
  'charset' => 'utf8mb4',
  'collation' => 'utf8mb4_general_ci',
  'prefix' => array(
        'default'   => '[Multisite DB].',
        'users'     => '[Main Site DB].',
        'sessions'  => '[Main Site DB].',
        'role'      => '[Main Site DB].',
        'authmap'   => '[Main Site DB].',
        'users_roles'   => '[Main Site DB].',
        'field_data_field_first_name'   => '[Main Site DB].',
        'field_data_field_last_name'   => '[Main Site DB].',
        'field_data_field_title'   => '[Main Site DB].',
  ),
);
0

The solution ended up being very simple.

I just had to change one line.

I changed this:

        'default'   => '[Multisite DB].',

to:

        'default'   => '',

This is how it looks all together.

$databases['default']['default'] = array(
  'driver' => 'mysql',
  'database' => '[Multisite DB]',
  'username' => '[Database Username]',
  'password' => '[Database Password]',
  'host' => '[DB Server IP]',
  'charset' => 'utf8mb4',
  'collation' => 'utf8mb4_general_ci',
  'prefix' => array(
        'default'   => '',
        'users'     => '[Main Site DB].',
        'sessions'  => '[Main Site DB].',
        'role'      => '[Main Site DB].',
        'authmap'   => '[Main Site DB].',
        'users_roles'   => '[Main Site DB].',
        'field_data_field_first_name'   => '[Main Site DB].',
        'field_data_field_last_name'   => '[Main Site DB].',
        'field_data_field_title'   => '[Main Site DB].',
  ),
);

I know that a lot of people use Bakery or are already on Drupal 8, but I hope this helps anyone still on Drupal 7 looking to share a User table across multiple websites with different databases.

  • Shared database tables is not necessarily fully supported by Drush; using other solutions are preferable, as you may run into problems with other commands. Glad you got this working for your setup though. – greg_1_anderson Nov 17 '17 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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