Verified and Tested 02/17/15

Introduction

In this article, we will go over how to add additional virtual hosts to a Linux VPS with Apache installed. Each virtual host handles a specific website or domain that will be hosted on the server, including sub-domains. This is referred to as named-based hosting because it allows multiple websites to utilize one set of resources, such as a single IP.

Prerequisites

This article assumes that you have already installed Apache and performed the basic configuration of it.

Setting up Apache Virtual Hosts on Ubuntu 14.04

All sites/hosts are located in the following directory:

/etc/apache2/sites-available/

If you have just installed Apache, these are the only things you should see:

Directory: /etc/apache2/sites-available/

Directory: /etc/apache2/sites-available/

Create a virtual host configuration file using your preferred text editor. In this example, nano is used.

nano /etc/apache2/sites-available/virtualhost.example.conf

Add a basic configuration to this file and save:

Sample Virtual Host configuration

Sample Virtual Host configuration

Some of the sections you may consider changing are:

<VirtualHost *:80>

This is the port that this virtual host will be accessible from. If we were to change 80 to 8080 then we would type the following URL to access the host: http:// virtualhost.example:8080

ServerName virtualhost.example
ServerAlias www.virtualhost.example

These values will indicate the domain that this virtual host will be representing and the alternate name for the host.

ServerAdmin [email protected]

Update this with your applicable server admin email address.

DocumentRoot /var/www/virtualhost.example/public_html

This will be the location of the site files for the specified domain.

Next enable the virtual host with the following command:

a2ensite virtualhost.example.conf

Your output should look like this:

a2ensite sample output

a2ensite sample output

Lastly, just restart Apache as indicated by the prompt

service apache2 reload