How to Configure Advanced Apache Server Redhat-7

Apache is Most Popular Web server which has rich features and Open Source , Most runs on UNIX based OS .

Topic We covered in this Post.

1.Apache Hosting

2.User Authentication


4.Virtual hosting (host multiple websites )

5.Port based Hsoting

Required RPM : http

Deamon : httpd

Configuration file: /etc/httpd/conf/httpd.conf

Configuration directory : /etc/httpd/conf.d

Note : I have already Configured the Yum on my machine for install the packages and it’s dependencies .

#yum install httpd –y (for install the httpd package)

Once we have installed the httpd Package (/var/www/html/) automatically created .

#vim /var/www/html/index.html (create a html file for our testing place some data inside this )

#vim /etc/httpd/conf.d/httpd.conf (configure the httpd file )


Note : Here we have to make entry in Hosts file if want to browse my website by name ,in real environment we use DNS server for name resolution .

#vim /etc/hosts

#systemctl restart httpd

#systemctl enable httpd

Allow Access from outside in firewall

#firewall-cmd –list-all (for list which services allowed in our firewall)

#firewall-cmd –permanent –add-service=http (for allow http service in FW )

#firewall-cmd –reload

Now we can browse our Webpage in Browser by our server IP

Now we can browse our website in browser .

User Authentication

Now we will authenticate our website with username/password.

#useradd tom (for create a user)

#htpasswd –c /etc/httpd/htpasswd tom ( set password for http authentication only)

#vim /etc/httpd/conf.d/httpd.conf (now add content to this file for allow users/group for authentication)

#systemctl restart httpd

Note : if you facing any error run he below command for verify the syntax of Configuration it with show the line no by which error occurred .

#httpd –t (for verify the httpd syntex if no error then Output “Syntex ok”)

Now it will ask for authentication then enter the credentials .

Add Restrictions

If we want to deny any particular IP or Entire network for access my Website do the following .

#vim /etc/httpd/conf.d/httpd.conf

Add below content in “httpd.conf” file for deny any particular ip or entire network range .

#systemctl restart httpd (restart the httpd service for apply the effects )

Host Multiple Websites on Single Server

#mkdir /var/www/html/mysites (create a new directory for place the new site data)

#vim /var/www/html/mysites/index.html (create a new webpage in new directory and fill some data inside file)

#vim /etc/httpd/conf.d/httpd.conf (add new site details in conf file)

#vim /etc/hosts (add host entry for site )

Do the Hosts file entry on client machine also if there is no DNS using for test environment .

#httpd –t

#systemctl restart httpd

Now can browse both websites .

Port Based Hosting and Change Apache default Directory

Apache directory default path is “/var/www/html” now we want to change it to new location .

#mkdir /root/sites (create a new dir on different path )

#vim /root/sites/index.html (create a webpage and fill some content )

We will change port and path for document root,add below content in conf file .

#vim /etc/httpd/conf.d/httpd.conf

Add the host entry of new site .

#vim /etc/hosts

Note : now we have to change Selinux context label of my new directory according to apache default directory .

#ls –dZ /var/www/html (for check the context lable of apache default directory )

#ls –dZ /root/sites/ (for check context of my new directory )

#semanage fcontext –at httpd_sys_content_t “/root/sites(/.*)?” (change the context )

#restorecon –Rv /root/sites (for apply the context)

#semanage port –l | grep http (for list the http ports in selinux)

#semanage port –at http_port_t –p tcp 8989 (for add the port in selinux for http)

#semanage port –l | grep http (now or new port 8989 also visible in ports)

Now open the main httpd conf file and change the documentroot line no :119 and directory line no:131 to our new path

#vim /etc/httpd/conf/httpd.conf

Now allow our http service in firewall so ther machines can access it .

#firewall-cmd –list-all (for check the allowed services in firewall)

#firewall-cmd –permanent –add-service=http (for allow http in firewall)

#firewall-cmd –reload

#systemctl restart httpd

Now we can browse our websites form other machine also but make sure add host file entry on your another machine if you don’t configure DNS server .

My sample host file of windows.

We have successfully configure Advanced apache server if face any challenge pls comment .

Leave a Reply

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