Multi-site Installation Options
There are three possible configurations for hosting more than one CiviCRM database on one server. These are all possible by using a single codebase or installation of CiviCRM.
The first alternative is to configure CiviCRM to host multiple sites so that each has a separate contacts (CRM) database and a separate content (CMS) interface. Each site is completely independent in operation from the other sites. The CivicSpace automatic installer is designed to handle this situation, but you can also manually configure this by following the instructions below.
The second alternative is to provide a common, shared content interface but with access to different contact databases. For example, an organization may set up separate CiviCRM databases for the different chapters of its organization, but provide access to these databases through a single interface.
The third alternative is for a shared contact database, but multiple, separate content interfaces. This may be used when an organization launches different sites for specific campaigns, or when organizations in a tight coalition are sharing contacts.
Manual Installations
 | Instructions Apply to v1.3+
These instructions are applicable to CiviCRM v1.3 and above. |
These instructions assume that CivicSpace or Drupal is configured to host multiple sites. In the root Drupal directory, there should be a sites directory; in the sites directory, there should be a directory for each site, in which there should be a Drupal configuration file (settings.php).
In each site's settings.php, check whether $base_url is set. This is noted as an optional setting, so it may not be already set, however it is recommended for CiviCRM.
Also, a copy of the CiviCRM configuration file (civicrm.settings.php) must be put in each site's directory. Variations in the CiviCRM configuration settings depend on the type of multi-site installation, and are described below.
 | Sharing a Single CiviCRM Codebase Via Symlinks
If your CiviCRM codebase is not located within the modules subdirectory of the root Drupal directory (for example, if there is a link from there to the CiviCRM codebase), then you need to create a file named 'settings_location.php' in the top-level directory of your codebase as follows:
<?php
define( 'CIVICRM_CONFDIR', '/home/lobo/public_html/drupal/sites/' );
?>
|
Separate CiviCRM Databases
Separate CiviCRM databases can be hosted on the same server in two ways:
The first method is to create a separate MySQL database for each CiviCRM database.
The second method allows all CiviCRM databases to be stored within a single database, by identifying records within the single database by domain IDs. By using this method, CiviCRM data for different organizations or communities can be separated within a single database. The default CiviCRM installation contains a single domain (domain ID: 1).
For each additional domain you want to support, use the automated SQL script that is included with CiviCRM 1.4+, which creates the required table entries for the next available domain ID.
To run this script from the command line:
- $ cd <drupal_root>/modules/civicrm/sql
- $ mysql -uUserName -pPassword DatabaseName < civicrm_add_domain.mysql
Or you can browse to <drupal_root>/modules/civicrm/sql/civicrm_add_domain.mysql in PHPMyAdmin and run the script within your existing CiviCRM database.
Shared codebase, separate content and contacts
If you have multiple Drupal sites that should be connected with separate CiviCRM databases, then you should have Drupal sites located in separate sites directories, and the CiviCRM data divided into separate databases or identified with domain IDs (as described above).
Each Drupal site must be configured individually to be associated with the right CiviCRM database. This is specified in the civicrm.settings.php file that should be in each site directory (along with the Drupal settings.php configuration file).
If you separated your CiviCRM databases by domain, then change the CIVICRM_DOMAIN_ID definition in each site's civicrm.settings.php to its corresponding domain ID (generated with the civicrm_add_deomain.mysql script and stored in the civicrm_domain table). Find the following line, and change 1 to the domain ID:
define('CIVICRM_DOMAIN_ID' , 1 );
If you separated your CiviCRM data into separate MySQL databases, then change the CIVICRM_DSN definition in each site's civicrm.settings.php to the corresponding database's name. Find the following line, and specify the user, password, domain, and database name for accessing the correct database:
define( 'CIVICRM_DSN' , 'mysql:
 | Additional Database Records Required for Multi-Domain CiviCRM Installs
Note: This is obsolete. This is not required if you use the civicrm_add_domain.mysql script described above.
If you decide to separate your CiviCRM contacts by assigning them to different 'domains' within the same database, you will need to create the following additional records in your CiviCRM DB tables:
- An additional domain record
- Domain-specific records for the customizable default constants used in CiviCRM (e.g. location types, relationship types, gender options, etc.).
Follow these steps:
- Modify the following SQL statement with appropriate values and run it against your CiviCRM DB to insert a new domain record:
INSERT INTO civicrm_domain( name, contact_name, email_domain )
VALUES ( 'Domain Name', 'Domain Contact Name', 'example.org' );
- Now verify the civicrm_domain.id of your new domain record (this will be 2 if it's the first additional domain created).
- Make a copy of the default data sql script that comes with civicrm (civicrm/sql/civicrm_data.mysql) - and edit as follows:
- Delete any insert queries that do NOT contain domain_id as one of the columns
- Edit the domain_id for all the remaining queries - changing it from 1 to the id of your newly inserted domain record
- Run your edited script against your CiviCRM DB
|
Shared codebase and content, separate contacts
To share content between the sites, all must use the same prefix and the same CiviSpace database as defined in each site's settings.php: $db_url[CRM:'default'] should be the same in all, and $db_prefix should be the same in all.
To separate the contacts, put unique values for each site in the corresponding civicrm.settings.php file:
define('CIVICRM_DOMAIN_ID' , 2 );
OR change the database that CiviCRM connects to:
define( 'CIVICRM_DSN' , 'mysql:
Note that the value for CIVICRM_DSN in civicrm.settings.php should be the same as the value in settings.php for $db_url[CRM:'civicrm'].
If you define different CIVICRM_DOMAIN_IDs then you need to use phpMyAdmin or a similar database interface to create a record in the civicrm_domain table with an appropriate id for each extra domain in the multi-site installation.
Shared codebase and contact, separate content
Create separate content for each site by storing its information in unique CivicCRM tables either by changing the prefix on the tables between the domains and/or changing the database that each CivicCRM site stores its data in. In other words, make sure to have a different combination of values for $db_url[CRM:'default'] and $db_prefix in each site's settings.php file.
To share the contact information between the sites, ensure the values are the same in all site settings files as follows:
define('CIVICRM_DOMAIN_ID' , 1 );
define( 'CIVICRM_DSN' , 'mysql:
$db_url[CRM:'civicrm'] = 'mysql:
Note that the value for CIVICRM_DSN and $db_url[CRM:'civicrm'] must be the same for each site.
Make each domain point to itself correctly - check: Administer > Global Settings > Resource URLs - making them point to the appropriate domains
See also: http://forum.civicrm.org/index.php/topic,1618.msg6991.html#msg6991
This doesn't quite work on 1.6 when sharing a single database for civicrm. I think you need the UI_uf_id index of civicrm_uf_match to be changed from:
UNIQUE INDEX UI_uf_id(
uf_id
)
to
UNIQUE INDEX UI_uf_id(
uf_id, domain_id
)
Yes, i should post a bug report somewhere else ...