How to Set Up a Multisite Configuration in Drupal

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:

Step 1: Set Up Your Drupal Installation

First, you need a base Drupal installation. Follow the standard procedure to install Drupal.

Step 2: Create Subdirectories for Each Site

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
    

Step 3: Create Settings Files

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
    

Step 4: Configure the settings.php Files

Edit the settings.php file in each site's directory to configure the database connection and other site-specific settings.

For example.com:


$databases['default']['default'] = array (
  'database' => 'example_com_db',
  'username' => 'db_user',
  'password' => 'db_pass',
  'host' => 'localhost',
  'port' => '',
  'driver' => 'mysql',
  'prefix' => '',
);
    

For example.org:


$databases['default']['default'] = array (
  'database' => 'example_org_db',
  'username' => 'db_user',
  'password' => 'db_pass',
  'host' => 'localhost',
  'port' => '',
  'driver' => 'mysql',
  'prefix' => '',
);
    

Step 5: Set Up Virtual Hosts

Configure your web server to handle requests for each site. Below are examples for Apache and Nginx.

Apache:

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
  

    

Nginx:

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;
  }
}
    

Step 6: Install Drupal for Each Site

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.

Step 7: Manage Sites

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

Card Image

How to Set Up a Local SSL Certificate on Apache: Step-by-Step Guide

Learn how to set up a local SSL certificate on Apache with this comprehensive step-by-step guide. Secure your local development environment with HTTPS.

Card Image

Latest Features of Coding Technology

Explore the latest features and advancements in coding technology, including new programming languages, frameworks, DevOps tools, AI integration, and more.

Card Image

Understanding Laravel Mix Webpack Configuration: Step-by-Step Guide

Step-by-step explanation of a Laravel Mix Webpack configuration file, including asset management for JavaScript, CSS, and Vue.js support.

Card Image

How Emojis Can Enhance Your Git Commits | Gitmoji Guide

Discover how to enhance your Git commits with emojis. Learn about the best practices for creating informative and visually distinctive commit messages.