First, install the httpd packages :

#  yum  install  httpd*

The main configuration file is httpd.conf which is present in /etc/httpd/conf/,  to edit :

#  vi  /etc/httpd/conf/httpd.conf

Go to the end of file and copy the last 7 lines and paste at the end.

  1. <VirtualHost *:80>
  2. #    ServerAdmin webmaster@dummy-host.example.com
  3. DocumentRoot [location of directory of web pages]
  4. ServerName  [name of site or server]
  5. #    ErrorLog logs/dummy-host.example.com-error_log
  6. #    CustomLog logs/dummy-host.example.com-access_log common
  7. </VirtualHost>

In the 1st line replace the  * with the ip address of server. You can do with the  * also but it will needed when you do the virtual hosting.

In the 3rd line give the path of the directory containing the web pages.

In the 4th line write the name of the site which you want to use.

Leave the other lines as it is.

Now, append the hosts file :

#  vi  /etc/hosts

[server IP]                [name of site or server]

And finally :

# service httpd start

Open your web browser and type the name of site or server.

——–Virtual Hosting———

Again copy and paste those 7 lines :

  1. <VirtualHost [ip address of server]:80>
  2. #    ServerAdmin webmaster@dummy-host.example.com
  3. DocumentRoot [location of directory of web pages]
  4. ServerName  [name of site or server]
  5. #    ErrorLog logs/dummy-host.example.com-error_log
  6. #    CustomLog logs/dummy-host.example.com-access_log common
  7. </VirtualHost>

But this time you must write the IP address of server in the 1st line in place of  *,  rest remains the same.

For virtual hosting to work you have to change one more setting.

#NameVirtualHost  *:80

This line is present 10-12 lines above those 7 lines. You have to uncomment this line and provide server IP address in place of  * .

Append the hosts file again, the IP address remains the same only the name of site is changed.

Reload or restart the httpd service.

Open your web browser and there you go…

Note: DNS server should be configured and service named should be running for website name resolution.