Drupal Technical
[Drupal] How to setup a multisite Drupal installation in your localhost?
If we want to run more than one site using a single Drupal installation we can use the multisite feature of Drupal. This multisite feature will allow us to share the core, contributed modules and themes among several sites. Nevertheless each sites has its own database and configuration. Read on to know how to setup a multisite Drupal installation in your localhost.
Follow the steps below to setup a multisite Drupal installation in your localhost
- Firstly open
/etc/hosts
in a text editor and add the following line to it
128.1.1.1 <site name> For eg:- 128.1.1.1 masco.local 128.1.1.1 lmaccc.local 128.1.1.1 msicallcenter.local
- Next go to
/etc/apache2/sites-available
- From there copy default to
eg:- masco.local - Create this file for each site.
- In the terminal type the command -
a2ensite <site name>
to enable the site
- Enable each site like this. Eg:- a2ensite masco.local
- After that you should restart Apache using a
sudo /etc/init.d/apache2 restart
<VirtualHost *:80 >
ServerName <site name>
DocumentRoot <path>
<Directory <path/>>
AllowOverride All
</Directory>
</VirtualHost>
Drupal Changes
Following are the changes to be made in your Drupal site
- Set the sites/default folder for the main site and then copy the 'default' folder for other sites and rename it with sitename.
- Create a separate database for each site.
- Export the shared tables if there are any and import these tables to a new database. Then delete these tables from all the main database.
- Then edit the settings.php to change
$db_url = 'mysqli://username:password@localhost/databasename'; Add $db_prefix = array( 'default' => '', 'users' => 'masco_shared.', 'sessions' => 'masco_shared.', 'role' => 'masco_shared.', 'authmap' => 'masco_shared.', 'sequences' => 'masco_shared.', 'users_roles' => 'masco_shared.', 'permission' => 'masco_shared.', );
to specify the shared database and tables.
- Then access each site in the browser and change the required admin settings.
Hope that helps.