How to install Apache on Ubuntu Amazon EC2 Instance – AWS

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

How to install Apache on Ubuntu Amazon EC2 Instance – AWS. Apache is the most widely used HTTP web server which provides dynamic loading modules, easily integrating with other applications.

This guide helps you to install Apache on Ubuntu 18.04 on AWS EC2 Instance and configure firewall (UFW).

This tutorial is tested on an AWS EC2 Instance with Ubuntu 18.04 AMI, So, this will work on any servers running Ubuntu 18.04.


  1. A running EC2 Instance. Learn how to create an AWS EC2 instance.
  2. Assigned a Elastic IP to your EC2 Instance.
  3. Successful SSH connection to your EC2 Instance.

SSH to your EC2 Instance and perform the steps listed below.

Install Apache

Let’s start by updating the local package index with the following command.

sudo apt update
sudo apt upgrade

Install Apache 2 package from the Ubuntu repository.

sudo apt install apache2

This will install apache2 and all required dependencies.

Setup Firewall

Now you can set up Uncomplicated Firewall (UFW) with Apache to allow public access on default web ports for HTTP and HTTPS

sudo ufw app list

You will see all listed applications.

Available applications:
Apache Full
Apache Secure
  • Apache: This profile opens 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)
  • OpenSSH: This profile opens port 22 for SSH access.

If you are not going to use SSL you need to enable only the Apache profile.

Now we will enable Apache Full.

sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'

With this command you can view the status of UFW.

sudo ufw status

You will see the output as follows.

Status: active
To Action From
-- ------ ----
Apache Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
Apache Full (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)

Check Apache Installation

Once Apache is installed is is started automatically and already be up and running.

Every process in Apache is managed with the systemctl command. Check the status of Apache with the following command.

sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
    Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Drop-In: /lib/systemd/system/apache2.service.d
    Active: active (running) since Tue 2020-01-06 03:59:34 UTC; 5min ago
  Main PID: 10617 (apache2)
     Tasks: 55 (limit: 667)
    CGroup: /system.slice/apache2.service
            ├─10617 /usr/sbin/apache2 -k start
            ├─10619 /usr/sbin/apache2 -k start
            └─10620 /usr/sbin/apache2 -k start
 Jan 06 03:59:34 apache systemd[1]: Starting The Apache HTTP Server…
 Jan 06 03:59:34 apache systemd[1]: Started The Apache HTTP Server.

Now visit the External IP address of your VM instance, you will see the default Apache welcome page.

Apache Welcome page

Apache Commands

To start Apache web server.

sudo systemctl start apache2

To stop Apache webserver.

sudo systemctl stop apache2

To restart Apache web server.

sudo systemctl restart apache2

To reload Apache without dropping connections.

sudo systemctl reload apache2

To disable Apache.

sudo systemctl disable apache2

To enable Apache.

sudo systemctl enable apache2

Become a Certified AWS Professional with this easy to learn course now.


Now you have learned how to install Apache and configure firewall (UFW) on AWS EC2 Instance.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.


  1. Kshitij Ajagaonkar Reply

    I used this steps to setup apache on ubuntu 20.04 on aws ec2 instance but once i completed this I am not able to connect to the ec2 instance. I don’t know what’s going wrong.

  2. Travis Hardaway Reply

    Yes, Do not use this tutorial anymore. It may have worked 2 years ago but now when you set UFW it caused problems and I can no longer SSH to my instance. Going to have to start over.

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.