How to configure Apache virtual hosts on Ubuntu 16.04 LTS

What is Apache?

Apache is a wonderful application software. It is the most widely used web server application in the world with over 50% participation in the commercial web server market. Apache is the most widely used web server application on Unix operating systems, but can be used on almost any platform, including Windows, OS X, OS / 2, and so on.

What is a virtual host?

The Apache web server can host multiple websites on a single server. You do not need a separate server and Apache software for each website. Perhaps you already know the virtual host of the VHost concept.


Before starting this tutorial, it should not be a non-root stand-alone account, that is, users with sudo privileges configured on the server. You can check the weather for the hard drive configured for Ubuntu 16.04.

Step 1. Install the Apache Web Server.

The Apache Web Server is one of the most popular web servers in the world. This is well documented. We can only install Apache with the Ubuntu package manager, apt. The package manager will install it, the Ubuntu software. You can simply choose here.

We can first write the following commands:

Now, Apache must be installed and able to provide HTML pages from the default document in / var / www / html.

You can do this by contacting or http: // localhost / on the local computer.

If Apache is installed, connect two Ubuntu machines via SSH or open a terminal session (according to Ubuntu Desktop), then follow these steps to configure a new virtual host.

Step 2. Create a directory

Assuming that is our virtual host website, we create a directory under / var / www, called

Step 3: Create a test HTML file.

Create an HTML file called index.html in the root directory created in the previous step and add the following HTML code.

Add the sample html content to the file and then save it.

Step 4. Create a virtual host file.

Apache comes with a default virtual host file named 000-default.conf, which can be used as a template for new virtual hosts. It is a normal virtual host. Att acts as a placeholder, but is not associated with the virtual host.

Copy the default virtual host with the following command:

Open the virtual host file:

The file should look like this:


As you can see in the DocumentRoot directive, files are provided from / var / www / html. We were inherited in the directory we thing on our stack. For example:

We also need to add a new ad that assigns the domain to this virtual host. This is done using the ServerName and ServerAlias directives. For example:


The final file should look like the following:

Step 5:Enable the New Virtual Host File

When you are finished, you need to restart Apache to make these changes take effect:

Step 6: Add domain information to the local host file:

Step 7: Check the site

Open a browser then type your domain name to test whether its working or not.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.