1

Using a Drupal Multisite system, is it possible to have a base set of configuration settings shared across multiple sites?

That is, each site in Drupal has a settings.php file

default/settings.php
site1/settings.php
site2/settings.php
anothersite/settings.php

Is there a master settings.php where I could set a configuration value once and have it apply to all my sites?

Or is this normally handled at the deployment level?

  • Anything wrong with adding require '/path/to/master.php'; to each of the settings.php files? – Clive Nov 4 '13 at 18:46
  • @Clive Ask the developers who take over this project and don't know about the master.php file. (but that's probably what I'll end up doing if there's no native Drupal solution) – Alan Storm Nov 4 '13 at 18:50
  • I'd imagine that info would be on the handover docs but I get what you're saying. Hard to think of a native Drupal solution, Because of the way settings.php is included I think you're out of luck (short of server wizardry, but that has the same problem you've already mentioned) – Clive Nov 4 '13 at 18:55
2

so for what it's worth using the default/settings.php as the master and then having each of the sites do a PHP include (as @Alan mentions) does work well! (I know this is an old question but I am working through multisite issues with Drupal 8 (8.6.13) and have come across this very thing...)

a couple of caveats:

1) I am managing the multisite installation and config manually so am creating my own settings.php files, not using drush site-install which will auto-generate the settings.php

2) you must do the include at the top of the site's settings.php and ensure that you are overriding only what you need to. (...or the inverse, that you are okay using the config in the default settings file)

I have this at the top of the settings.php for each site:

$default_path = "sites/default";
include $app_root . '/' . $default_path . '/settings.php';

and then override the database settings - setting the prefix etc:

$databases['default']['default'] = array (
  'database' => 'this_is_the_database',
  'username' => 'username',
  'password' => 'password',
  'prefix' => array(
    'default'         => 'site1_prefix_',
  ... etc

and the site name:

$config['system.site']['name'] = 'Site 1 Name will override default site name';

of course YMMV

tl;dr - yes you can, but be aware of the order in which your PHP will execute and apply the settings

1

The general consensus seems to be

No, you can't do that

without resorting to a raw PHP include.

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.