Install and setup multisite drupal on CentOS 6.5

In this tutorial we will learn, how to install and setup multisite drupal on CentOS 6.5 . In multisite , we will do single drupal installation and create multiple website on it. It helps us to manage multiple website.

In multisite, each upgrade need to be done once. Whereas each site has its own database and configuration settings. Hence each sites have its own content,settings, enabled modules and themes.

Note:
* If the sites are similar in functionality (use same modules or use the same drupal distribution) do it.
* If the functionality is different don’t use multisite

Security Concerns

(Reference : https://drupal.org/documentation/install/multi-site#security )
You might want to reconsider using Drupal’s multi-site configuration, in situations where the administrators for all of the sites being run from the same code base are not either the same person or a small group with a high level of mutual trust. The reason is that anyone with full administrative privileges on a Drupal site can execute arbitrary PHP code on that site through various means (even without FTP access to the site), and that arbitrary PHP code could be used from one site to affect another site, if the two sites are in the same HTTP document root and sharing the same Drupal code.

So, unless you completely trust all of the administrators of the sites you are considering running from the same Drupal code base to be knowledgeable, careful, and not malicious, you might want to consider installing their Drupal sites in completely separate areas of the web server that are not able to affect each other via PHP scripting.

Summary:
We are creating 2 drupal sites.The domain names are given below
1. example.com
2. example2.com

Steps To Setup Multisite Drupal

Follow the given below steps to install drupal and making it as multisite.

Step 1 : Install Apache HTTP Server, MySQL Server and wget command

Web Server = Apache HTTP Server
Database Server = MySQL
wget(command) is for downloading the package(drupal).

yum install httpd mysql-server wget

Step 2 : Install PHP and required php modules

yum install php php-mysql php-pdo php-common php-cli php-gd php-mbstring php-dom

Step 3 : Download drupal package

Download latest drupal package from Drupal site .
By using wget command, we are downloading the drupal package

wget http://ftp.drupal.org/files/projects/drupal-7.28.tar.gz

Note: Druapl version 7.28 is latest stable version. Recommend to download and use always latest stable version.

Step 4 : Untar the Drupal tarball and extract to /var/www/html/directory

Use tar command to extract the package.

tar -xvzf drupal-7.28.tar.gz -C /var/www/html/

Step 5 : Rename the extracted out drupal directory

Rename the directory which is extracted out from untar command.

mv /var/www/html/drupal-7.28/ /var/www/html/drupal

Step 6 : change to directory /var/www/html/drupal/sites

cd /var/www/html/drupal/sites

Step 7 : List the Dir/Files in /var/www/html/drupal/sites

[root@localhost sites]# ls -l
total 16
drwxr-xr-x 4 6226 6226 4096 May  8 09:35 all
drwxr-xr-x 2 6226 6226 4096 May  8 09:35 default
-rw-r--r-- 1 6226 6226 2365 May  8 09:35 example.sites.php
-rw-r--r-- 1 6226 6226  904 May  8 09:35 README.txt
[root@localhost sites]#

Step 8 : Copy default directory to your domain name

Now copy the directory called default and give copied directory name with your domain name.Here, I am using the domain name example2.com . This will be your site directory.

[root@localhost sites]# cp -prvf default example2.com

Step 9 : Rename default.settings.php file

Rename the file called default.settings.php to settings.php . This file is located inside site directory which has your domain name.(As per tutorial, it is in example2.com)

[root@localhost sites]# mv example2.com/default.settings.php  example2.com/settings.php

Step 10 : Create directory called files inside site directory

[root@localhost sites]# mkdir -p example2.com/files

Step 11 : Change ownership and group of Drupal directory

Change the ownership and group with apache to Drupal directory

cd ~
chown -R apache:apache /var/www/html/drupal/

Create MySQL Database,user name for Drupal sites

Lets restart the MySQL server . If it is your fresh installation of MySQL server on system, we will recommend you to run the command mysql_secure_installation . By running this command, you can set root password and secure your server in some aspects.

Now after root password is set, follow the given below commands to create database for each site.
Here, we have two sites with following details-

Site 1: exmaple.com
Database name for site 1 : example
Database username for site 1 : exampleuser
Password set for database user : Password (Change password of your wish)

Site 2: example2.com
Database name for site 2 : example2
Database username for site 2 : example2user
Password set for database user : Password (Change password of your wish)

mysql -u root -p
After login you will get the mysql prompt like this
mysql >
Now create a user and set the password. Use strong password
mysql> CREATE USER 'exampleuser'@'localhost' IDENTIFIED BY 'Password';

mysql> create database example;

mysql> GRANT ALL ON example.* TO 'exampleuser'@'localhost';
mysql> flush privileges;

mysql> CREATE USER 'example2user'@'localhost' IDENTIFIED BY 'Password';

mysql> create database example2;

mysql> GRANT ALL ON example2.* TO 'example2user'@'localhost';
mysql> flush privileges;
mysql> exit

Configure Apache HTTP Server for Drupal Sites

Now we are configuring Apache HTTP Server for Drupal Sites.
First take the backup of httpd.conf file. In case any problem happen you can revert back.


cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.`date +%F`

Here we are configuring here Name Based Virtual Hosting

First, search the keyword NameVirtualHost in httpd.conf file . Then make it enable by removing # from the front of line.Make it available for all domain at port 80.Like given below

NameVirtualHost *:80

Now paste the below given code in last line of httpd.conf file. You can make changes as per your requirement


    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /var/www/html/drupal
   ServerName example.com
    ErrorLog logs/example.com-error_log
    CustomLog logs/example.com-access_log common


    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /var/www/html/drupal
   ServerName example2.com
    ErrorLog logs/example2.com-error_log
    CustomLog logs/example2.com-access_log common

Now restart the apache http service

service httpd restart

Installing Drupal sites with web interface

Installing drupal sites is easy through web interface. Be ready with informations like Database name, database user name and its password.
In screenshots it is quite visible to see the credentials which we are going to use.

Open the web browser(chrome/firefox). In address URL field, write the domain name which you want to install.
As per our practical, we are installing example2.com first.
Below given screenshots are step by step

Install your first drupal site

drupal-example-1

drupal-example-2

drupal-example-3

drupal-example-4

drupal-example-5

drupal-example-6

Now logout from the drupal dashboard. And just simply type your domain name.(here we are opening the site example2.com, I have changed the theme to make some differentiation in two sites.)
This how it appears-
example2-site

Install your second drupal site

The steps are same for all. Now we have to open the next drupal site name which we want to install.
Here, in this case we are installing now example.com
Use only MySQL credentials for example.com . Read the section,”Create MySQL Database,user name for Drupal sites”

Below given is the step by step installation with screenshot.

drupal install

example-drupal-2

example-drupal-4

example-drupal-5

example-drupal-6

example-drupal-7

Logout from drupal dashboard. After loging out, simply open your domain name. Here as per practical we are opening example.com

example-site

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.