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!

Share:

Leave a Reply

Your email address will not be published. Required fields are marked *