VirtualHosts in Apahce2


Apache is the most widely used open source HTTP server. It is a cross-platform web server. A more detailed definition is found on or


I want to set up a VirtualHost on my laptop so that I can start working on a website that
I am working on.


Website client : mr.X
web address(URL):
web server: Apache_HTTP_Server
Scripting Engine : PHP


  • The main focus here is to set up the web server to serve the website for mr. X.
  • The website  using

VirtualHost configuration

Assumptions and considerations

  1. All the VirtualHost configuration mentioned here are found in the Apache manual page
  2. I assume that you have already installed Apache web server and scripting engine.
  3. You are using a GNU/Linux System especially Debian derivatives. If you don’t know what
    I am talking about now. Please wait for a little while till I publish one or Google them up.
  4. All the website data is located under /var/sites/www.mrx.orgNOTE
    • I always follow this directory layout where all the sites are stored under /var/sites/ and individual sites will be named in the same way as their DNS i.e, will be stored as follows /var/sites/

Actual VirtualHost configuration

Filename : /etc/apache2/sites-available/

<VirtualHost *:80>
  # Address of the server
  # Email address for the web master
  # Where the website data is located
  DocumentRoot /var/sites/
  # Specify permissions on who can access this site
  <Directory /var/sites/ >
     Options Indexes FollowSymLinks MultiViews
     AllowOverride None
     Order allow,deny
     Allow from all
  </Directory >

Now save the file under /etc/apache2/sites-available/ and execute the following.

$ sudo mkdir -p /var/sites
$ sudo mkdir -p /var/sites/
$ sudo a2ensite
$ sudo service apache2 restart

Now open your hosts file found in /etc/hosts and enter the following details and save it.

 # this is a default content of the file /etc/hosts
 # DO NOT DELETE THE FOLLOWING ENTRY!    localhost    localhost.localdomain

#Instead add your entries below
# Add entry for this will be used as a DNS

Now you can access your web-site as