• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to create VirtualHost in Apache Web Server

August 21, 2013 by Sharad Chhetri Leave a Comment

In this tutorial we will learn how to create VirtualHost in Apache Webserver.
I believe you have already installed the apache web server in CentOS or Red Hat.(How to install apache web server)
With the help of VirtualHost we can host many domains or website from single Web Server.
This is a simple example to start with your first VirtualHost configuration in Apache Webserver.

I have used a few terms which is required for setting up the basic VirtualHost configuration.

DocumentRoot : This is used to define the Data path of website.In this example it is at /var/www/html/example.com. You can give other data path also
ServerAdmin : The contact person email id, Here I have given webadmin@example.com. You can also give root@localhost or your own email id. Customize as per your requirement
ServerName : Fully Qualified domain Name of server ,use hostname -f command to get FQDN of webserver. My server has FQDN as webserver.example.com

Optional:
DirectoryIndex : This is webserver main page or index page. It can be any with suffix index and applicable file format like index.html,index.php etc
ErrorLog As the name suggest it is for keeping log of web server.Here we have give the path /var/log/httpd/error_log which is already bydefault present there. You can customize this path as per your requirement
CustomLog: Here we have customize our webserver logging and all output will be log in file called /var/log/httpd/access_log . You can see common logformat has been used.
To know more about logformat ,read this link

Setup VirtualHost In Apache Web Server

This is an example of setting Virtual Host

Step 1: Change directory to /var/www/html

cd /var/www/html

Step 2: Create a directory called example.com

mkdir example.com

Step 3: Create index.html file inside example.com directory

vi example.com/index.html

Hello world

Step 4: Take backup of/etc/httpd/conf/httpd.conf file.

cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.orig

Step 5: Edit /etc/httpd/conf/httpd.conf and in last line write down the below given content



    ServerAdmin webadmin@example.com
    DocumentRoot /var/www/html/example.com
    ServerName webserver.example.com
    DirectoryIndex index.php
    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log common

Step 6: Now restart the apache web service

/etc/init.d/httpd restart

Step 7: Now open the web browser and in address bar type http://ip-address-of-webserver

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to set htdigest password in apache web server
  2. How to install Apache Web Server on Ubuntu 14.04 LTS (Trusty Tahr)
  3. Install pagespeed module ( mod_pagespeed ) on Apache Web Server : CentOS / RHEL
  4. AttributeError: ‘WSGIRequest’ object has no attribute ‘session’ Django python web framework
  5. How to install and remove Apache webserver in Ubuntu and Debian
  6. How to install mod_proxy and setup reverse proxy in Apache Ubuntu
  7. Find installed and enabled apache module in Debian/Ubuntu
  8. How to install apache webserver in CentOS and Red Hat
  9. Access Control by host and ip address in Apache 2.4
  10. Gitweb not displaying correctly apache MIME issue CentOS 6.4

Filed Under: Apache, Linux Tagged With: apache, CentOS, redhat, webserver

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

How to zip the directory in linux with command line

How to encode and decode the strings with base64

Could not find make anywhere!!! Please edit the config section to include the path to make. at ./install.pl line 2101

Read the file inside compressed .gz files without extract

How to convert rpm file into deb file

How to see system load average in terminal with graphical representation

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy