Setting up a multisite configuration in Drupal allows you to run multiple websites from a single Drupal codebase. Follow this step-by-step guide to achieve this setup:
First, you need a base Drupal installation. Follow the standard procedure to install Drupal.
In your Drupal installation, navigate to the sites
directory and create a new directory for each site you want to manage. For example, if you want to create two sites, one for example.com
and one for example.org
, create the following directories:
cd /path/to/drupal/sites
mkdir example.com
mkdir example.org
Copy the default settings file (default.settings.php
) into each new directory and rename it to settings.php
.
cp /path/to/drupal/sites/default/default.settings.php /path/to/drupal/sites/example.com/settings.php
cp /path/to/drupal/sites/default/default.settings.php /path/to/drupal/sites/example.org/settings.php
settings.php
FilesEdit the settings.php
file in each site's directory to configure the database connection and other site-specific settings.
example.com
:
$databases['default']['default'] = array (
'database' => 'example_com_db',
'username' => 'db_user',
'password' => 'db_pass',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
);
example.org
:
$databases['default']['default'] = array (
'database' => 'example_org_db',
'username' => 'db_user',
'password' => 'db_pass',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
);
Configure your web server to handle requests for each site. Below are examples for Apache and Nginx.
Edit your Apache configuration file to include virtual hosts for each site.
ServerName example.com
DocumentRoot /path/to/drupal
AllowOverride All
Require all granted
ServerName example.org
DocumentRoot /path/to/drupal
AllowOverride All
Require all granted
Edit your Nginx configuration file to include server blocks for each site.
server {
listen 80;
server_name example.com;
root /path/to/drupal;
location / {
try_files $uri /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
server {
listen 80;
server_name example.org;
root /path/to/drupal;
location / {
try_files $uri /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
Now, visit each site's URL (e.g., http://example.com and http://example.org) to run the Drupal installation process. Follow the installation steps, and each site will use its respective database.
You can now manage each site independently via their respective URLs. Any module or theme updates only need to be done once, as they share the same codebase.
This setup allows you to efficiently manage multiple sites while maintaining a single Drupal codebase.
Published By: Krishanu Jadiya
Updated at: 2024-07-28 15:44:35