How to configure apache virtual host on ubuntu 16.04


In this tutorial we will guide you to configure apache virtual host or vhost on ubuntu 16.04. Using virtual hostĀ  allow the administrator to use one server to host multiple domains or sites off of a single interface or IP by using a matching mechanism. Basically you can you one ip address to server multiple domain name. Virtual host method is widely use in shared hosting provider.

Before you begin with this guide, you should at least have basic knowledge of linux, know basic shell command for linux, root user or non-root user account with sudo privileges set up on your server. Also you have been installed apache. If your server not installed apache you can follow How To Install Apache PHP on Ubuntu 16.04 Tutorial.

You must have point your domain name to your server IP Address

For the example in this tutorial we will create virtual host with these following details

Domain name :

Document root : /var/www/

Step 1 – Create the Directory Structure

Document root is the top-level directory that Apache looks at to find content to serve. Usually using name public_html to make easy recognize.

For instance, for our sites, we’re going to make our directories like this:

Step 2 – Create Example Page for Virtual Host

We will create simple html file and put to virtual host document root

In this file, create a simple HTML document that indicates the site it is connected to. My file looks like this:

Step 3 – Create New Virtual Host Configuration Files

Apache comes with a default virtual host file called 000-default.conf used for default or to catch undefined virtual host. We will use asĀ  templates to create our virtual host.

Create our virtual host configuration file based on 000-default.conf file using these following command

Open new virtual host configuration file using nano

Edit that file become like this

Note , you can use ServerAlias to create virtual host with different name but have same document root , for example and . The configuration will be like these

Step 4 – Enable the New Virtual Host Configuration to Apache

Now that we have created our virtual host files, we must enable them. Apache includes some tools that allow us to do this.

We use aen2site to enable configuration

You need to restart Apache to make these changes take effect

Step 5 – Test in Your Browser

Open your browser , in this example we will open url

You should see a page that looks like this


Congratulation , you have been successfully configure apache virtual host on ubuntu 16.04


You may also like...

Leave a Reply

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