Categories: Ubuntu

Install Apache2 on Ubuntu 20.04 or 20.10

Make sure your Ubuntu is up to date and patched.

$ sudo apt update
$ sudo apt upgrade

Apache is available within Ubuntu’s default software repositories, making it possible to install it using conventional package management tools. After confirming the installation, apt will install Apache and all required dependencies.

Step 1: Install Apache

$ sudo apt install apache2 -y

After that, the Apache2 web server and its all dependencies will be installed on your system. Once installed, verify the version of the Apache server as follows:

$ apache2 -version

# OUTPUT
Server version: Apache/2.4.41 (Ubuntu)
Server built:   2020-08-12T19:46:17

Step 2: Apache Firewall Options

It’s necessary to modify the firewall settings to allow outside access to the default web ports before testing Apache. You should have a UFW firewall configured to restrict access to your server.

# Check UFW status 
$ sudo ufw status

# OUTPUT
Status: inactive

# List the UFW application profiles by typing:
$ sudo ufw app list

# OUTPUT
Available applications:
  Apache
  Apache Full
  Apache Secure
  CUPS

There are three profiles available for Apache:

  • 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)

It is recommended that you enable the most restrictive profile that will still allow the traffic you’ve configured. Since we haven’t configured SSL for our server yet in this guide, we will only need to allow traffic on port 80:

# Set Apache as selected profile and check UFW status 
$ sudo ufw allow 'Apache'

#OUTPUT
Rules updated
Rules updated (v6)

$ sudo ufw enable

#OUTPUT
Firewall is active and enabled on system startup

$ sudo ufw status

# OUTPUT
Status: active

To                  Action      From
--                  ------      ----
Apache              ALLOW       Anywhere 
Apache (v6)         ALLOW       Anywhere (v6) 

Managing Apache2 service on Ubuntu

To start, stop, restart and then find the service status again use the following commands.

# Start the apache2 server
$ sudo systemctl start apache2.service

# Stop the apache2 server
$ sudo systemctl stop apache2.service

# Restart the apache2 server
$ sudo systemctl restart apache2.service

# Reload the apache2 server gracefully
$ sudo systemctl reload apache2.service

# Find the status of apache2 server
$ sudo systemctl status apache2.service

Have fun!

Emre KARABULUT

Hi, I’m Emre KARABULUT, 29, and I am the owner of a small (but perfectly formed) design studio called Minimalist Art & Design based in Istanbul, which specialises in Blog and User Interface design. I help entrepreneurs and small business owners create a unique brand and online presence which gives them a powerful platform to reach out to their customers and markets.

Recent Posts

Authenticating with the Apple Search Ads API

There are many methods for using APIs. In order to understand it better, lets take…

4 years ago

How To Add Swap Space on Ubuntu 20.04 or 20.10

One way to guard against out-of-memory errors in applications is to add some swap space.…

4 years ago

Install Docker-Compose on Ubuntu 20.04 or 20.10

Docker Compose is a tool that allows you to run multi-container application environments based on…

4 years ago

Shopware 6 – Local installation in Ubuntu 20.04 or 20.10

After the creation of development environment your setup fulfills the Shopware 6 requirements. If you…

4 years ago

Shopware 6 – Docker installation in Ubuntu 20.04 or 20.10

After the creation of development environment your setup fulfills the Shopware 6 requirements. If you…

4 years ago

Shopware 6 – Installing System Requirements in Ubuntu 20.04 or 20.10

To create a development environment in fresh install of Linux - Ubuntu 20.04 (Focal Fossa)…

4 years ago