Project

General

Profile

Actions

{{last_updated_at}} by {{last_updated_by}}

CiviCRM multisite

Here are my notes on configuring multisite on Drupal 8 with CiviCRM. Unless a step is marked as "do every time", it only needs to be done when you add your second domain and not subsequently. While his is Drupal 8-specific, the general process is the same regardless. See also my older docs on the Palante Tech wiki.

Multisite Setup

  • Change /etc/hosts (dev only) do every time.
  • Add a wildcard DNS entry
  • Add a ServerAlias to Apache config (*.agbu.megaphonetech.com) - both HTTP and HTTPS config. Also on HTTP remove the rewritecond that references the main site name directly. Restart Apache.
  • Run certbot, including ALL URLs: sudo certbot -d california.crm.agbu.org -d crm.agbu.org -d donate.agbu.org -d california.donate.agbu.org. do every time
    • This will expand the existing cert. Wildcard certs can only be renewed by creating a new TXT record every 90 days, so enumerate the sites.
  • Update settings.php, "trusted_host_patterns" (with a wildcard, e.g. '^.+.crm\.agbu\.org$').
  • Install the Multisite Permissioning extension.
  • cv api MultisiteDomain.create debug=1 sequential=1 name="California" is_transactional=0 do every time
  • In Drupal (8), enable "Domain", "Domain Access", "Domain Alias", "Domain Configuration" modules.
  • Add domain records in Configuration » Domains. do every time
    • Add Domain Aliases (with no redirect) to the corresponding test/local sites, so they don't break when you pull in a copy of the live database. do every time
  • Update civicrm.settings.php with the multi-site switch, also BASEURL etc. do every time.
  • Update civicrm.settings.php to hardcode the following directories, otherwise they need setting per-domain: php $civicrm_setting['Directory Preferences']['customPHPPathDir'] = '[cms.root]/sites/all/civicrm/extensions'; $civicrm_setting['Directory Preferences']['extensionsDir'] = '[cms.root]/sites/all/civicrm/extensions'; $civicrm_setting['URL Preferences']['extensionsURL'] = '[cms.root]/sites/all/civicrm/extensions';
  • Enable multisite in Civi for the domain. do every time.
  • Create a new role "Subdomain User".
  • Grant that role "View all Contacts in Domain" and "Edit All Contacts in Domain" and "View All Groups in Domain" permissions.
  • Disable any ACLs that could apply to users in the subdomain, they'll be ANDed with the domain permissions above.

Dev/Test sites

While the steps for setting up dev/test sites are basically the same as above for site 2, on site 3 the only change necessary is to the switch statement in civicrm.settings.php.

Copying settings

You'll often want to copy the existing settings to the new domain. First review the settings you'll be copying with the first SQL statement, then copy them with the second SQL statement. Change the domain IDs appropriately.

-- View settings for new domain:
SELECT d1.id, d1.name, d1.domain_id, d1.contact_id, d1.is_domain, d1.component_id, d1.created_date, d1.created_id, LEFT(d1.value, 60)
FROM civicrm_setting d1
LEFT JOIN civicrm_setting d3 ON d1.name = d3.name AND d1.domain_id = 1 AND d3.domain_id = 3
WHERE d1.name NOT IN ('navigation','domain_group_id')
AND d3.id IS NULL
and d1.domain_id = 1;

-- Now insert
INSERT INTO civicrm_setting (name, domain_id, is_domain, component_id, value)
SELECT d1.name, 2, d1.is_domain, d1.component_id, d1.value
FROM civicrm_setting d1
LEFT JOIN civicrm_setting d2 ON d1.name = d2.name AND d1.domain_id = 1 AND d2.domain_id = 2
WHERE d1.name NOT IN ('navigation','domain_group_id')
AND d2.id IS NULL
and d1.domain_id = 1;

Updated by Jon Goldberg almost 4 years ago · 2 revisions