Virtual Host (vhost) use on Apache / Linux

The Virtual Host or vHosts allow the hosting of several domains on a same system usually having only one public IP.


At first, your system need at least Apache if not a LAMP structure (Linx/Apache/MySQL/PHP). If necessary, we install it via the following command :

This tutorial provides details about how to host the and on the same system.


Then we are going to implement the arborescence needed to establish our vhost to manage both domains :

We give the rights matching the folders www, and

We created 2 pages HTML by default for each web sites :

vHost creation

From now on, we can move to the creation of our vhost by copying the default configuration file :

By default, both files and will look like the following result :

So we are going to change and add the following elements which will be adapted to both domains :

The email address included by the server in error messages sent to the client.

Arborescence’s root of the documents, the php function realpath can help you to get the information if necessary.

Hostname and port used by the server to authenticate itself.

Other server’s names used to reach virtual servers based on name.

Now you must activate the 2 vhosts via a2ensite which is included in Apache then relaunch Apache :

Local configuration

It is possible that your domains may not be available for various reasons.
In this case, we are going to change the local configuration of your system to test your vhosts:

Your machine’s IP to change.

Both your sites are now operational as long as the DNS zones are properly configured.

Virtual Host (vhost) use on Apache / Linux