How to Install and configure apache web server in centos 7

How to Install and configure apache web server

Install and configure Apache web server step by step:-

What is an Apache web server?
Ans:- Apache is a freely available web server that is distributed under an “open source” license.
Apache web server is one of the most secure and popular open source 
http server. It can be used to host anything from personal websites to corporate domains.

What is httpd?
httpd is an apache hypertext transfer protocol (http) server program. It is designed to be run as a standalone daemon process. When used like this will create a pool of child process or threads to handle requests.

In Apache two type of hosting we are done.
Virtual hosting: -
1. Name-based:- Single IP or multiple hosting
2. IP base:-  multiple
 IP multiple hosting :

To configure apache web server follow below process
We need to install the
 httpd package.

# yum install -y httpd

Then start httpd service

#sudo service httpd start

Then we need to do some entry in the httpd configuration file.
Httpd configuration file /etc/httpd/conf/httpd.conf

# vim /etc/httpd/conf/httpd.conf
<VirtualHost *80>
    DocumentRoot “/var/www/html”

Save the configuration file.
Then restart 
httpd service with below command

# sudo service httpd restart

To check apache web server configure well

# httpd -t

Now open your favorite browser. In url section type
It’s open apache default web page.

* How to do Virtual Hosting
IP based hosting:- Multiple IP or multiple websites.
Name-based hosting:- Single IP multiple websites.

IP based hosting: - first of all we need to create two sites in document file a document root file path is /var/www/html .

# cd /var/www/html/
# mkdir site1
# mkdir site2
# vim site1/index.html
This is my first site
# vim site2/index.html
This is my second site

Save both files.
Then we need to edit Apache config file :-

# vim /etc/httpd/conf/httpd.conf
    DocumentRoot “/var/www/html/site1”

    DocumentRoot “/var/www/html/site2”

then save the file.
Restart the Apache service with following command.

# sudo service httpd restart

Open your browser type ip in url section.
Result: -
This is my first site.
Result: -
This is my second site.

Name Based Hosting:-
Open httpd configuration file and edit with given entry.

# vim /etc/httpd/conf/httpd.conf
    DocumentRoot “/var/www/html/site1”

    DocumentRoot “/var/www/html/site2”

After that need to do some entry in name based hosting.

# vim /etc/hosts    site1    site2

Then restart httpd service

# sudo service httpd restart

Open your browser and access site with a name based in url type.
Result:-         This is my first site.
Result:-         This is my second website.

Thanks for visit us.
If you have any query comment below.

Blog type: 

Add new comment

Authored By

Sandeep Gurjar

Hy all, This is Sandeep Gurjar am the founder of I am a Redhat Certified Engineer (RHCE) / AWS Solutions Architect-Associate and working as an system administrator since 2016.

Follow us on

Facebook​  Twitter  LinkedIn  Google+