How to Install and Configure Apache Web Server on Ubuntu 20.04

How to Install Apache on Ubuntu

Apache is one of the most well-known web-server. It is an open-source and cross-stage HTTP/HTTPS server that controls an enormous level of the Internet’s sites. Apache gives numerous ground-breaking features that can be stretched out through extra modules. This instructional exercise describes how to install and configure the Apache webserver on Ubuntu 20.04.

Quick Guide for Install Apache on Ubuntu 20.04

Before starting with the article, make sure you have a root user or sudo privileged user. Point the domain to the server IP to get the output as the very last image.

Apache Installation

Apache is already present in the Ubuntu repositories.

The installation process is quite clear. On Ubuntu and Debian operating systems, the Apache and its service is called apache2.

Run these below commands to update the packages first and install Apache:

sudo apt update -y
sudo apt install apache2 -y

When these commands will be executed, As a result, Apache will be installed and the service will automatically start.

Now, Just verify that the service is running with the following command:

sudo systemctl status apache2

You will get something like this as output, And that will tell you about the service’s current status and auto boot status of service:

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-08-08 19:28:40 UTC; 2min ago

That’s pretty much it to successfully install Apache on Ubuntu 20.04 server, Let’s proceed further.

Open HTTP and HTTPS Ports

Apache webserver listens on two-port 80,443 HTTP and HTTPS respectively. We need to open these two ports in the default installed firewall so we can access the webserver from outside using the Internet.

Read Also: How To Install MySQL 5.7 and 8.0 In Ubuntu 20.04

By default Ubuntu uses UFW, so we can enable both ports in the firewall by issuing the below command:

sudo ufw allow 'Apache Full'

This Apache Full will enable both the ports.

We can verify the change by the following command:

sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
Apache Full                ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
Apache Full (v6)           ALLOW       Anywhere (v6)

Verify the Apache Installation

To confirm that everything works effectively, open any browser, put your server IP address http://YOUR_IP_OR_DOMAIN/ in the URL bar, and you will see the Ubuntu 20.04 Apache default welcome page as below image:

verify the Apache Installation
Ubuntu Apache Welcome Page

This page shows some fundamental information about further Apache configuration, some helper scripts, and directory locations.

Configure Virtual Host

A Virtual Host is a part of the Apache configuration directive. It will permit us to run more websites on a single server. Normally, a virtual host represents one website.

Apache comes with one enabled virtual host by default. Any domain that pointed to the server IP address in the DNS zone, will match with the default virtual host. If you are planning to host only one website, you simply can upload your site content in /var/www/Html as it is the default document root for the default virtual host, and the virtual host configuration file will be /etc/apache2/sites-enabled/000-default.conf file, so you can edit this file if you need to make any further changes.

On the off chance, you need to have more than one site. Then you’ll have to do a virtual host setup for each site. In this part, we’ll set up a site with a domain called “”. You need to supplant “” with your owned domain name.

The initial step is to create a document root directory. That’s where we will put our website files for our domain name. Run the below command to make the directory:

Create Directory

sudo mkdir -p /var/www/

For the testing aspect, create an index.html the file inside the just created document root directory:

vim /var/www/

Copy and paste the following content in the index.html file.

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <meta charset="utf-8">
    <title>Welcome to</title>
    <h1>Success! home page!</h1>

Save and close the index.html when you are done.

To avoid any permission issues, update the ownership of the document root directory to the apache user (www-data):

sudo chown -R www-data: /var/www/

The subsequent stage is to make a virtual host configuration file for the “”. The best practice is to store each vhost config in a separate file.

Apache vhosts files are located in /etc/apache2/sites-available directory. The best method to name the file is according to the domain.

Edit configuration file

Open your preferred text editor and create the following file:

vim /etc/apache2/sites-available/

Copy and paste the following content in your Apache configuration

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/

    <Directory /var/www/>
        Options -Indexes +FollowSymLinks
        AllowOverride All

    ErrorLog ${APACHE_LOG_DIR}/
    CustomLog ${APACHE_LOG_DIR}/ combined


Apache doesn’t read the config files located in the /etc/apache2/sites-available directory unless they are connected to the /etc/apache2/sites-enabled directory.

So to enable the vhost configuration, we need to create a symlink using the below command:

sudo a2ensite

To test the configuration for any kind of syntax errors issue below command:

sudo apachectl configtest

If everything will be okay, you will see the output something like this:

Syntax OK

Now it’s time to restart the Apache service so our changes can take effect:

sudo systemctl restart apache2

Now, to verify if the setup is properly completed, open in your browser, and you will see something like this:

Apache success page


In this article, you have got to know how to install Apache on Ubuntu 20.04. Now, You’re ready to deploy your applications and use Apache as a webserver.

If you have any questions or feedback, leave a comment.