Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web.

LET’S GET STARTED…………………………….

Step 1:- Install Apache web server

on CentOS/RHEL:

Sudo yum install httpd

on Ubuntu/ Debian:

sudo apt-get update
sudo apt-get install apache2

Step 2:- create Directory Structures and add Demo page for virtual hosts

Apache server is using /var/www as a document root of static content
Lets create a folder name inside this www directory

cd /var/www
sudo mkdir bangmetric.com
sudo vi index.html

Add the below content in index.html

<!DOCTYPE html>
<html>
<head>
<title>Sample Page</title>
</head>
<body>

<h1>This is a Sample Page for Bangmetric Pvt. Ltd</h1>
<p>This is sample paragraph for Bangmetric Pvt. Ltd</p>

</body>
</html>

save and exit

Step 3:- Create Virtual hosts file

Virtual host files are what specify the configuration of our separate sites and dictate how the Apache web server will respond to various domain requests

Create two directories sites-available and sites-enabled. sites-available directory will keep all of our virtual host files, while the sites-enabled directory will hold symbolic links to virtual hosts that we want to publish

sudo mkdir /etc/httpd/sites-available
sudo mkdir /etc/httpd/sites-enabled

Now we should tell apache that virtual host file is present in site-available directory by doing this

sudo vi /etc/httpd/conf/httpd.conf

Add below line at the end file

 IncludeOptional sites-enabled/*.conf 

save and exit

Now create virtual Hosts File

sudo vi /etc/httpd/sites-available/bangmetric.com.conf

add the below content

<VirtualHost *:80>

    ServerName www.bangmetric.com
    ServerAlias bangmetric.com
    DocumentRoot /var/www/bangmetric.com/
    ErrorLog /var/www/bangmetric.com/error.log
    CustomLog /var/www/bangmetric.com/requests.log combined
</VirtualHost>

save and exit

Step 4:- Enable New virtual server files

we can create a symbolic link for each virtual host in the sites-enabled directory.

sudo ln -s /etc/httpd/sites-available/bangmetric.com.conf /etc/httpd/sites-enabled/bangmetric.com.conf

Restart the apache server

Sudo systemctl restart httpd

Step 5:- Test Your Result

http://<yourdomain>

Its look like this

Congratulations…..Now you can use single centos server and host multiple domains

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