Install and Configure Apache2 on Ubuntu Server 16.04

In this tutorial we are going to learn how to install and configure Apache Web Server on Ubuntu 16.04. We will also learn How to Configure a Virtual Host on Ubuntu Apache Web Server.

Following are the steps we are going to follow.

  1. Install Ubuntu Apache2 Web Server.
  2. Configure Apache Virtual Host on Ubuntu 16.04.

Install Ubuntu Apache2 Web Server

The Apache server for Ubuntu server 16.04 provides by the apache2 package. We can install apache2 on Ubuntu 16.04 using apt-get install command.

sudo apt-get update

sudo apt-get install apache2

This will install the Apache HTTP web server on your Ubuntu Server 16.04.

To check the Apache installation, try to access the localhost using wget command.


Once you run the wget command, index.html file should be downloaded to your current working directory.

You can also try to access the Apache Web Server from a remote computer. From the remote computer, open the web browser and type the IP Address of your Ubuntu server in the Address bar. You should get the Ubuntu Apache default web page as the response.

Install and Configure Apache2 on Ubuntu Server 16.04

Ubuntu Apache Default Web Page

Default document root for apache web server in Ubuntu 16.04 is /var/www/html directory. You can host your static website by just putting the content of your website to /var/www/html folder.

Configure Apache Virtual Host on Ubuntu Server 16.04

Using apache virtual host we can host multiple website on our Ubuntu Web Server. For this tutorial I am going to create a new virtual host for the domain

First, create the document root using the mkdir command(Document root is the location, where we put html files of our website).

sudo mkdir /var/www/

sudo chgrp www-data /var/www/

sudo chmod 750 /var/www/

Create a sample index.html file inside the /var/www/ folder.

echo 'This is' > /var/www/

Next, we need to create the Apache virtual host configuration file for The configuration file should create inside the /etc/apache2/sites-available/ directory with .conf extension.

touch /etc/apache2/sites-available/example.conf

Then open the example.conf file and add the following configuration.

<VirtualHost *:80>



DocumentRoot /var/www/


CustomLog ${APACHE_LOG_DIR}/ combined


Finally, enable the site using a2ensite command and restart the Ubuntu Apache2 Web Server.

a2ensite example.conf

systemctl restart apache2.service

This way you can host unlimited number of domains on your Ubuntu Server. To access the website using the domain name through the Public Internet, You need to point the domain name to the IP Address of the Ubuntu Server (You can do this through your domain registrar).

Summary - Install Apache Ubuntu Server 16.04

In this tutorial we learned how to install Apache Web Server on Ubuntu Server 16.04.

  • To Install the Apache Web Server on Ubuntu, we installed apache2 package using apt-get install command.
  • Then, We learned how to Configure Apache Virtual Host to Host Multiple websites on our Ubuntu Web Server.
submit to reddit