How to Host multiple Websites on Apache2

March 29, 2012 in Apache Configuration

How to Host multiple Websites on Apache2

Let’s say that we own 2 or more domain names ( and We also have 2 web pages (hostpage1 and hostpage2). But we have only 1 webserver and 1 public IP (for this example i will use local IP but it will be the same if you own a public static IP)

Setting up the Domain names.

First thing is to create an “A record” in the DNS of your Domain Names to point “www” to your public or local IP address of your Web Server. I use local DNS in this example. So i will point the “www” for both of my domain names to So it will be something like that: –> –>

Now if i ping or i will receive reply from the same ip (in my case This IP is the IP of my Web Server. Test that everything is ok by typing in a terminal:

ping www.”the name of your domain name”

You should get reply from the Public IP of your web server:

In this example i use the following:



Setup directories for webpages

Now I will create 2 directories for my Web Pages (Hostpage1 and Hostpage2) in the directory named /var/ do that by opening a terminal and typing:

cd /var/

sudo mkdir hostroot

cd hostroot

sudo mkdir hostpage1

sudo mkdir hostpage2

Now i have 2 directories (hostpage1 and hostpage2) inside the “hostroot” directory. I will copy my 2 homepages, for my 2 domain names, inside my 2 directories and i will name both pages, as index.php(in this 2 directories you should copy your websites). So it will be something like the following



|    |–>index.php



Configure Apache

The last thing i have to do is to edit “/etc/apache2/sites-available/default” do that by typing in a terminal:

sudo gedit /etc/apache2/sites-available/default

add the following lines at the end of this document

<VirtualHost *:80>

DocumentRoot /var/hostroot/hostpage1



<VirtualHost *:80>

DocumentRoot /var/hostroot/hostpage2



Save the file and exit.

now restart Apache2 by typing in a terminal

sudo /etc/init.d/apache2 restart

Open a browser and navigate to and

You can do that to host multiple sites in your Web Server.

A video tutorial will be available soon so stay tuned!