How to Install Apache on Ubuntu 20.04

How to Install Apache on Ubuntu 20.04

Apache is one of the most popular web servers in the world. This is an open-source and cross-platform HTTP server that supports most Internet websites. Apache provides many advanced features that can be expanded through additional modules.

This tutorial explains how to install and manage an Apache web server on Ubuntu 20.04.


Before starting with the tutorial, make sure you are logged in as a user with sudo privileges.

Install Apache

Apache is included in Ubuntu’s default repository.

Installation is quite easy. On Ubuntu and Debian systems, the Apache package and its service are called apache2.

Run the following command to update the package index and install Apache:

sudo apt update
sudo apt install apache2

During the installation process, completing the Apache service will automatically start.

You can verify that Apache is running by typing:

sudo systemctl status apache2

The output will tell you that the service is running and is activated to start on system boot:

Output :

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

That’s it, you have successfully installed Apache on your Ubuntu 20.04 server, and you can start using it.

Open HTTP and HTTPs Ports

Apache listens on ports 80 (HTTP) and 443 (HTTPS). You must open the port on your firewall so that the web server can be accessed from the Internet.

Assuming you are using UFW, you can do this by activating the ‘Apache Full’ profile which includes rules for both ports:

sudo ufw allow 'Apache Full'

Verify the change:

sudo ufw status

Output :

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)

Verifying the Apache Installation

To verify that everything is functioning correctly, open your browser, type your server’s IP address http: // YOUR_IP_OR_DOMAIN /, and you will see the default Apache 20.04 Apache welcome page as shown below:


This page includes some basic information about Apache configuration files, helper scripts, and directory locations.

Setting up a Virtual Host

Virtual Host is an Apache configuration directive that allows you to run more than one website on one server. Usually a virtual host describes one website.

Apache is shipped with one virtual host that is activated by default. All domains that point to the server’s IP address will match the default virtual host. If you are hosting a single website, you can upload the contents in / var / www / html and edit the virtual host configuration found in /etc/apache2/sites-enabled/000-default.conf file.

If you want to host more than one website, you must create a virtual host configuration for each site. In this section, we will set up a website for a domain called “”. You must replace “” with your domain name.

The first step is to create a document’s root directory where website files for the domain name will be stored and presented in response to requests. Run the following command to create a directory:

sudo mkdir -p /var/www/

For testing purposes, create an index.html file in the domain document’s root directory:

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

Save and close the file when finished.

To avoid permission issues, change ownership of the domain document’s root directory to Apache users (www-data):

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

The next step is to create a virtual host configuration for the “” domain. The best practice is to save each vhost configuration in a separate file.

Apache vhosts files are stored in the / etc / apache2 / sites-available directory. The standard naming convention is to give a file name according to the domain.

Open your text editor and create the following file:

<VirtualHost *:80>
    DocumentRoot /var/www/

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

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

Apache does not read configuration files found in the / etc / apache2 / sites-available directory unless they are connected to the / etc / apache2 / sites-enabled directory.

To enable virtual host configuration, create a symlink using the a2ensite utility:

sudo a2ensite

Test the configuration for each syntax error by:

$ sudo apachectl configtest

If there are no errors, you will see the following output:

Output :

Syntax OK

Restart the Apache service for the changes to take effect:

$ sudo systemctl restart apache2

Finally, to verify that everything works as expected, open in your browser, and you will see something like this:



We have shown you how to install Apache on Ubuntu 20.04. You are now ready to start using your application and use Apache as a web or proxy server.

If you have questions or feedback, don’t hesitate to leave a comment.

Related posts

How to set up NFS Server on CentOS


How to Change the Time Zone in Ubuntu 20.04


How to Install TeamViewer on Ubuntu 20.04


How to use the chmod command on Linux


How to Overcome Python & AI with this Extensive Training Package


How to Set Up Automatic Kernel Updates on Linux


How to Install Microsoft TrueType Fonts on Fedora


How to Install Steam on Ubuntu 20.04


How to Install TensorFlow on Ubuntu 20.04