Virtual hosting is a method for hosting multiple domain names on a single server. The are two types of virtual hosting: “Name-based virtual hosting” and “IP-based virtual hosting.” With the name-based virtual hosting, you can host multiple websites on a single machine with a single IP address.

Here, we are going to host two websites – namely “www.virtualhost1.com” and “www.virtualhost2.com” – on a single IP “192.168.1.227” on the Apache web serve, the most popular web server in the world.

Note: while Ubuntu 14.04 server is used for this tutorial, the instructions will be similar for most Linux distros.

Getting Started: Installing Apache

First, you need to update your system and then install Apache.

To do this, run the following command:

sudoapt-get updatesudoapt-get install apache2

To verify whether the Web server is working or not, open the web browser and navigate to the URL http://192.168.1.227/ (assuming that your server IP address is 192.168.1.227).

You should see that the Apache web server is working.

Create Virtual Directories

First, you need to make a directory structure that will hold the website data that we will be serving to clients.

Create two directories for the websites “www.virtualhost1.com” and “www.virtualhost2.com.”

Setting Up Ownership and Permissions

By default, Apache service runs as a “www-data” user in Ubuntu. Both virtual directories that we created earlier are owned by root. You must change the ownership of these two virtual directories to “www-data,” so that Apache can read and write data.