Project

General

Profile

CiviCRM multisite » History » Version 1

Jon Goldberg, 04/23/2020 07:14 PM

1 1 Jon Goldberg
{{last_updated_at}} by {{last_updated_by}}
2
# CiviCRM multisite
3
4
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](https://redmine.palantetech.coop/projects/commons/wiki/CiviCRM_multi-site_checklist).
5
6
### Multisite Setup
7
* Change /etc/hosts (dev only) **do every time**.
8
* Add a wildcard DNS entry 
9
* 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.
10
* Run certbot: `sudo certbot -d california.crm.agbu.org -d crm.agbu.org -d donate.agbu.org -d california.donate.agbu.org`
11
 * 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.
12
* Update settings.php, "trusted_host_patterns" (with a wildcard, e.g. `'^.+.crm\.agbu\.org$'`).
13
* Install the [Multisite Permissioning](https://civicrm.org/extensions/multisite-permissioning) extension.
14
* `cv api MultisiteDomain.create debug=1 sequential=1 name="California" is_transactional=0` **do every time**
15
* In Drupal (8), enable "Domain", "Domain Access", "Domain Alias", "Domain Configuration" modules.
16
* Add domain records in **Configuration » Domains**. **do every time**
17
 * 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**
18
* Update civicrm.settings.php with the multi-site switch, also BASEURL etc. **do every time**.
19
* Update civicrm.settings.php to hardcode the following directories, otherwise they need setting per-domain:
20
```php
21
  $civicrm_setting['Directory Preferences']['customPHPPathDir'] = '[cms.root]/sites/all/civicrm/extensions';
22
  $civicrm_setting['Directory Preferences']['extensionsDir'] = '[cms.root]/sites/all/civicrm/extensions';
23
  $civicrm_setting['URL Preferences']['extensionsURL'] = '[cms.root]/sites/all/civicrm/extensions';
24
```
25
* Enable multisite in Civi for the domain. **do every time**.
26
* Create a new role "Subdomain User".
27
* Grant that role "View all Contacts in Domain" and "Edit All Contacts in Domain" and "View All Groups in Domain" permissions.
28
* Disable any ACLs that could apply to users in the subdomain, they'll be ANDed with the domain permissions above.
29
30
### Dev/Test sites
31
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`.
32
33
### Copying settings
34
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.
35
36
```sql
37
-- View settings for new domain:
38
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)
39
FROM civicrm_setting d1
40
LEFT JOIN civicrm_setting d3 ON d1.name = d3.name AND d1.domain_id = 1 AND d3.domain_id = 3
41
WHERE d1.name NOT IN ('navigation','domain_group_id')
42
AND d3.id IS NULL
43
and d1.domain_id = 1;
44
45
-- Now insert
46
INSERT INTO civicrm_setting (name, domain_id, is_domain, component_id, value)
47
SELECT d1.name, 2, d1.is_domain, d1.component_id, d1.value
48
FROM civicrm_setting d1
49
LEFT JOIN civicrm_setting d2 ON d1.name = d2.name AND d1.domain_id = 1 AND d2.domain_id = 2
50
WHERE d1.name NOT IN ('navigation','domain_group_id')
51
AND d2.id IS NULL
52
and d1.domain_id = 1;
53
```