Setup Apache Virtual Hosts On Ubuntu 15.04 / 14.04

Apache We Server
Apache We Server

Virtual Hosting is used to host multiple websites on single web server, web server might be anything of Apache HTTP,Microsoft IIS, Lighttpd etc. This guide will show you how to setup Apache virtual hosts on Ubuntu 15.04, also, this should work on Ubuntu 14.04 / 14.10.


1. Types of Virtual Hosting

2 Assumptions

3. Install Apache Webserver

4. Setup Apache virtual hosts

5. Verifying Virtual Hosts

Types of Virtual Hosting:

There are two type of Virtual Hosting in web server, Name based and IP based. With the Name based virtual hosting, we can configure multiple website on single ip address, in ip based, we can configure only one website on single ip address. Apache supports both name and ip based virtual hosting, virtual host should be configured using the virtual host container, typical virtual  host container look like below.


For a demo, we will be using Ubuntu 15.04 server, and we will be hosting two websites named “www.itzgeek1.local and “www.itzgeek2.local“.

Server Host Name: server.itzgeek.local
IP Address:

Install Apache Webserver:

Before installing Apache, update the repositories.

sudo apt-get update

Install Apache Webserver using following command.

sudo apt-get install apache2

Once it is installed, system will automatically start the Apache service. To test your installation, open up a web browser, and point to the URL. or http://ip-add-ress
Ubuntu 15.04 - Apache Virtual hosts
Ubuntu 15.04 – Apache Virtual hosts

If you get a web page like above, apache is working fine. Now, we can proceed to setup apache virtual hosts.

Setup Apache virtual hosts:

Create public directories:

Create a public directory, it holds all the data files, and it will be served when ever the request comes to the apache web server from clients.
Create a two directory for our websites, “www.itzgeek1.local” and “www.itzgeek2.local“.

sudo mkdir -p /var/www/html/www.itzgeek1.local
sudo mkdir -p /var/www/html/www.itzgeek2.local

Create demo page for Virtual Hosts:

Now, we have to create a index.html file in the both directories, and this will be served by the apache web server.
Create a index.html for “www.itzgeek1.local” virtual host.

sudo nano /var/www/html/www.itzgeek1.local/index.html

Place the below content into the file.

<h1>Welcome To www.ITzGeek1.local website</h1>

Create a index.html for “www.itzgeek2.local” virtual host.

sudo nano /var/www/html/www.itzgeek2.local/index.html

Place the below content into the file.

<h1>Welcome To wwww.ITzGeek2.local website</h1>

Setting up directory ownership and permissions:

By default, apache service runs as a www-data user. Now, both virtual directories that we created earlier are owned by root, we must change ownership to www-data, so that apache can do write and read data.

sudo chown -R www-data:www-data /var/www/html

Also, you can make virtual directories world readable.

sudo chmod 755 /var/www/html/

Now, we are all set to create a configuration files for virtual hosts.

Create Virtual Host files:

Now, create a virtual host file “www.itzgeek1.local.conf for the virtual host “www.itzgeek1.local, virtual host files should end with .conf extension. Lets create a first virtual host file.

sudo nano /etc/apache2/sites-available/www.itzgeek1.local.conf

Add the following content into the file.

<VirtualHost *:80>

ServerAdmin [email protected]
ServerName www.itzgeek1.local
DocumentRoot /var/www/html/www.itzgeek1.local

ErrorLog ${APACHE_LOG_DIR}/www.itzgeek1.local_error.log
CustomLog ${APACHE_LOG_DIR}/www.itzgeek1.local_ccess.log combined


Same way, create a second virtual host file.

sudo nano /etc/apache2/sites-available/www.itzgeek2.local.conf

Place the following content into the file.

<VirtualHost *:80>

ServerAdmin [email protected]
ServerName www.itzgeek2.local
DocumentRoot /var/www/html/www.itzgeek2.local

ErrorLog ${APACHE_LOG_DIR}/www.itzgeek2.local_error.log
CustomLog ${APACHE_LOG_DIR}/www.itzgeek2.local_ccess.log combined


After creating the virtual host files, enable new virtual host that we created just now by creating symlink to sites-enabled directory.

sudo ln -s /etc/apache2/sites-available/www.itzgeek1.local.conf /etc/apache2/sites-enabled/

sudo ln -s /etc/apache2/sites-available/www.itzgeek2.local.conf /etc/apache2/sites-enabled/

Restart the apache service.

sudo service apache2 restart

That’s All!!, we have successfully Setup Apache Virtual Hosts on Ubuntu 15.04.

Verifying Virtual Hosts:

If you use Linux system, edit “/etc/hosts” file.

sudo nano /etc/hosts

Add below entries.  www.itzgeek1.local  www.itzgeek2.local

If you use windows based machines, edit “hosts” file in “C:\Windows\System32\drivers\etc” directory.

Open up your browser and point to the URL http://www.itzgeek1.local or http://www.itzgeek2.local. You should see the demo pages which we created earlier.

www.itzgeek1.local demo page:

Ubuntu 15.04 - Apache Virtual hosts - VH 1
Ubuntu 15.04 – Apache Virtual hosts – VH 1

www.itzgeek2.local demo page:

Ubuntu 15.04 - Apache Virtual hosts - VH 2
Ubuntu 15.04 – Apache Virtual hosts – VH 2

You can add the actual domain name records in your DNS server. So that, you don’t have to add a host entry on the each and every remote or local system. Similarly, you can create and host as many as sites you want.


Virtual Host:


Share This Post