How to set up Apache Virtual Hosting in CentOS/Rhel 7.x

How to set up Apache Virtual Hosting in CentOS/Rhel 7.x

Prerequisites : https://www.natsav.com/blog/2016/11/26/how-to-install-apache-on-centosrhel-7-x/

Setup the Virtual Host

create directory for website

#mkdir -p /var/www/html/virtualhost

Create test web pages for virtual host

#vim /var/www/html/virtualhost/index.html

Add the following content on the above Html file

<html>

<head>
<title>www.virtualhost.com</title>
</head>

<body>
<h1>The “virtualhost.com” virtual host is working!</h1>
</body>
</html>

and save the above Html file.

Create a virtual host configuration file

#vim /etc/httpd/conf.d/virtualhost.conf
Add the following content in virtual host configuration file

<VirtualHost *:80>
ServerName www..com
ServerAlias virtualhost.com
DocumentRoot /var/www/html/virtualhost/
</VirtualHost>

Add the following line in the hosts file

#vim /etc/hosts

192.168.43.2 virtualhost.com

Now restart the service

#systemctl restart httpd
Now open the browser and go to the URLs http://virtualhost.com

Leave a Reply

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