Drupal 7.x multi-site set-up and configuration
- Setting up multisite
- Drupal Install
domain2to share users, user roles and session with
- Test your sites
Drupal has been known for its multisite feature but it lacks detailed documentation on how to set-up and configure it.
The following multi-site setup and configuration features the following:
A multi-site with a domain name for each site; A multi-site with one shared core files, modules and themes; and A multi-site with separate databases for each site but with an option to share common users, sessions and user roles.
- The domain names nameservers (ns1, ns2, …), or the DNS A record should have been pointed to the server already;
- The virtual host configuration file of the domain names in the server should have been set to point to the same directory in the server; and
- The main Drupal instance is already setup and running. Herein we call its domain name, domain1.com.
In the sites/ directory, duplicate the
cd sites cp example.sites.php sites.php
sudo nano sites.php
Add the following at the bottom of
sites.php: (Don’t forget to replace
$sites['domain1.com'] = 'domain1.com'; $sites['domain1.com/domain2.com'] = 'domain2.com';
sites/default/ directory to
# Assuming we are in sites/ directory. cp default/default.settings.php domain2.com/default.settings.php
sites/domain2.com/ directory, create
files directory. We will change permissions of files directory to public.
# Assuming we are in sites/domain2.com/ directory. mkdir files sudo chmod 777 files
sites/domain2.com/ directory, duplicate
# Assuming we are in sites/domain2.com/ directory cp default.settings.php settings.php
That’s it. We are ready for the next step.
Install Drupal to
domain2.com by going to the domain name using a browser. Just install it the way the first domain
domain1.com has been installed with the following important notes:
- That it should use the same database, and not another database; and
domain2.commust use a different table
prefix_. The database of
domain1.comdoes not need to have a prefix, but encouraged to have one. For this purpose, let’s assume that
domain2.comuse the following prefixes:
Navigate to sites/domain2.com/ directory.
sudo nano settings.php
Go to the
$databases variable and change the value of
$databases['default']['default']['prefix'] from its non-array value to an associative array value. The array must contain the following information
default = 'd2_' users = 'd1_' sessions = 'd1_' role = 'd1_' authmap = 'd1_'
Or, you can copy-paste the following into the value of prefix.
array( 'default' => 'd2_', 'users' => 'd1_', 'sessions' => 'd1_', 'role' => 'd1_', 'authmap' => 'd1_', )
The above shows that
domain2's default database has the prefix of
d2_ but with the users, sessions, role and authmap tables, it will use the tables of
Test your sites by going to
If there is a problem with
domain2, try to clear your cache.