How To Install Apache On Ubuntu 20.04

In this post, I will guide you on How To Install Apache On Ubuntu 20.04. Apache is the most widely used web server in the world.

To start, you should prepare yourself a VPS running Ubuntu operating system. We choose to use VPS provided by Vultr to bring speed and stability to the website. If you have not used any VPS service, please click here to sign up for an account and get $100 for free.

About Apache Web Server

Apache is one of the most popular web servers in the world. It is an open-source and cross-platform HTTP server that provides a large percentage of Internet sites. The Apache Web Server is a web server that offers many powerful functions. These include dynamic load modules, powerful media support, and extensive integration with other popular software.


Before starting the installation, we must have a regular user with sudo privileges configured on the machine. Furthermore, we have to enable a firewall to block unnecessary ports. Once we have all of this, we can log in as this non-root user to get started.

Installing Apache

sudo apt update

Apache is available in Ubuntu’s default software repositories. For this reason, we’ll start by updating the local package index for the latest changes.

Then, install the apache2 package.

sudo apt install apache2

Once installed, you can check the installed Apache version with the following command:

sudo apache2ctl -v

Setting up the Firewall

If your server is using a firewall please perform the following steps to allow external access to the web server.

List the application by ufw with the command:

sudo ufw app list

You will receive a list of the application profiles:

Available applications:
  Apache Full
  Apache Secure
  • Apache: This profile opens only port 80 (normal, unencrypted web traffic).
  • Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic).
  • Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic).

Usually, “Apache Full” will be used to open ports 80 and 443 for web access.

sudo ufw allow 'Apache Full'

Check the results using the command:

sudo ufw status

Checking your Apache Web Server

After installing apache, Ubuntu 20.04 automatically starts the Apache web server. Check the status of Apache as follows:

sudo systemctl status apache2

Use your browser access by link:


You should see the default Ubuntu 20.04 Apache web server page.

Default Apache Web Server Page

Managing Apache

To stop web server:

sudo systemctl stop apache2

To start Apache:

sudo systemctl start apache2

To restart the web server:

sudo systemctl restart apache2

If you are simply making configuration changes, Apache can often reload without dropping connections.

sudo systemctl reload apache2

By default, Apache is configured to start automatically when the server boots. Disable this behavior by typing:

sudo systemctl disable apache2

Setting Up Virtual Hosts for Website Domain

First, we need to create a directory containing the code. For example, it is possible to create a directory in /var/www/your-domain with the command below:

sudo mkdir /var/www/your_domain

You can then upload the source code to this directory via FTP or SFTP.

sudo nano /var/www/your_domain/index.html

And add your code in the index.html file.

sudo nano /etc/apache2/sites-available/your_domain.conf

And copy the content below into your_domain.conf file:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName your_domain
    ServerAlias www.your_domain
    DocumentRoot /var/www/your_domain
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Then execute the command below to activate the virtual host just configured.

sudo a2ensite your_domain.conf

Test for configuration errors.

sudo apache2ctl configtest

If successful, you will see a line appear.

Syntax OK

Finally, Restart apache to make the changes.

sudo systemctl restart apache2

Now you can access the website by domain name with the link http://your-domain.

This is the end of the How To Install Apache On Ubuntu 20.04.

Follow us for the more helpful posts!

We hope this is a useful post for you.

You can read more useful posts like How To Configure Country Options In Magento 2.

Thank you for reading!

4.4 7 votes
Article Rating

Aaron LX

Aaron is a passionate writer, crazy about shopping, eCommerce and trends. Besides his outstanding research skills and a positive mind, Aaron eagerly shares his experience with the readers.

Leave a Reply or put your Question here

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x