Web Hosting Virtual Configuration Host multiple websites | Arkit

Using a single Linux VPS – Virtual Private Server or Linux Server you can run multiple websites. It’s called Web Hosting using a virtual configuration in Linux.  Virtual hosting is a method for hosting multiple domain names on a single server. This allows one server to share its resources, such as memory and processor cycles, without requiring all services provided to use the same hostname.

VirtualHost Prerequisites

  • Install Apache packages (yum install httpd)
  • Create multiple directories under default path (/var/www/html/)
  • Domain name pointing to your Private/Public server IP (In this example we will use webserver1.com and webserver2.com)
  • Need Sudo privileges (or root) to install packages

Install Web Server Packages and enable ports

If you do not have yum configured do the below steps to configure the EPEL repository


# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm


# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Now install the apache/webserver package using the below command

# yum install httpd* -y

Enable and start service

# systemctl enable httpd.service
# systemctl start httpd.service

Allow Firewall ports to communicate external clients with webserver

# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload

Web Hosting Virtual configuration

In RHEL7 /Centos 7 simple steps to enable the webserver to host multiple websites. Creating directory structure for multiple website content.

# mkdir -p /var/www/html/webserver1/
# mkdir -p /var/www/html/webserver2/
# touch /var/www/html/webserver1/index.html
# touch /var/www/html/webserver2/index.html

Edit index.html file and add few lines of HTML code to display while browsing websites

<h1>Welcome to WebServer1</h1>

similar way edit webserver2 index file and change statement to webserver2

Add entries in the host’s file to resolve IP to name

# vi /etc/hosts webserver1 www.webserver1.com webserver2 www.webserver2.com

Writing VirtualHost config for web hosting

Goto Default HTTPd configuration path create multiple config files for multiple websites hosting

# vi /etc/httpd/conf.d/webserver1.conf<VirtualHost *:80>
ServerAdmin root@localhost
ServerName www.webserver1.com
DocumentRoot /var/www/html/webserver1
DirectoryIndex index.html
ErrorLog /var/www/html/webserver1/error.log
CustomLog /var/www/html/webserver1/requests.log combined

<Directory "/var/www/html/webserver1">
AllowOverride none
Require all granted

VirtualHost config explanation

  • ServerAdmin – For any website config change notifications
  • ServerName – Is the actual public domain name (Example: server-computer.com)
  • DocumentRoot – Web site files store location
  • DirectoryIndex – Default website file name when you first browse the website

Now verify the syntax

# httpd -t
syntax ok

Reload / Restart Web Server Services to effect configuration

# systemctl restart httpd.service

Client-side open browser and browse using website URL’s


That’s it. Both websites are up and running within a single VPS Or Linux Server.

Related Articles

For More Linux Articles

SSH Access Slow how to resolve

Thanks for your wonderful Support and Encouragement

Ravi Kumar Ankam

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

Leave a Reply

Your email address will not be published. Required fields are marked *