DevOps
Install and Configure Apache2 on Ubuntu EC2
Walk through apt install apache2 on a public Ubuntu AMI, then unblock HTTP with UFW and an EC2 security group so the default Apache page loads in a browser.

Hello, everyone. I am Shashikant Dwivedi, and in this walkthrough I wire up Apache so a bare Ubuntu image on AWS EC2 can answer HTTP on port 80 like any other small VPS.
Apache spins up an HTTP listener fast; the slow part is almost never apt install but the firewall sandwich between UFW on the instance and the security group in the console. When I stack Nginx on similar boxes I still paste the same Ubuntu install and UFW snippet first so apt and firewall muscle memory stays consistent across stacks.
Prerequisites
You need an Ubuntu Server instance on AWS (or another cloud) with SSH access using your key pair. Grab the public IPv4 from the EC2 console and confirm port 22 is open in the instance security group before you chase HTTP issues.
SSH into your Ubuntu EC2 instance
Open the Instances tab on your EC2 dashboard, copy the IPv4 public address, and connect from a terminal. This is the same ssh -i … user@ip pattern I use whenever I SSH into AWS EC2; only the username changes with the AMI.
ssh -i private-key.pem ubuntu@your-public-ip



Update and upgrade packages with apt
Refresh the package index, then apply upgrades so apache2 pulls current dependencies.
sudo apt-get update
sudo apt-get upgrade


Install Apache2 with apt
Install the apache2 meta-package; apt install apache2 wires the service units you will verify in a minute.
sudo apt-get install apache2

Configure UFW for Apache Full and SSH
Check whether UFW is active; if it is inactive, turn it on before you lock yourself out.
sudo ufw status
If this shows status: inactive, enable it:
sudo ufw enable


Allow both the bundled Apache profile and SSH so remote administration survives the change. ufw allow 'Apache Full' maps to HTTP and HTTPS together, which saves another edit when you later terminate TLS on the box.
sudo ufw allow 'Apache Full'
sudo ufw allow '22'


Open HTTP port 80 in your EC2 security group
With UFW sorted, hop back to the EC2 console and edit the attached security group so HTTP reaches the instance (EC2 security group HTTP port 80 is the checklist item people skip after hardening Linux).
Open Security groups from the EC2 instance view.

Open the Inbound rules tab and choose Edit inbound rules.

Add an HTTP rule (TCP 80) sourced from the internet (for example 0.0.0.0/0), save, and wait a few seconds for propagation.

Verify the default Apache welcome page
Paste the instance public IP into a browser; you should see the stock Apache2 Ubuntu landing page.

Frequently asked questions
Do I need both UFW and an EC2 security group rule for HTTP?
Yes. UFW filters packets once they reach the Ubuntu network stack, while the security group filters at the AWS edge. Both must permit TCP 80 for anonymous browser traffic to succeed.
What does the UFW Apache Full application profile open?
Apache Full is a canned UFW profile that allows HTTP (80) and HTTPS (443) in one command, which lines up with how I evolve a host from plain HTTP to TLS without relearning rules.
Can I follow these steps on Ubuntu outside EC2?
The apt install apache2 and UFW portions work on any Ubuntu Server image. The cloud-specific work is whatever sits in front of the box; on EC2 that is the security group, elsewhere it might be another firewall or upstream NAT.
How do I SSH into my instance if ubuntu is the wrong username?
Check the AMI docs: Amazon Linux often uses ec2-user, while many Ubuntu images still ship ubuntu. Keep ssh -i your-key.pem user@public-ip, and make sure port 22 stays allowed while you troubleshoot. The Nginx-focused paste board uses the same boring apt + ufw rhythm I reach for after any new SSH session.
When is Apache a reasonable choice versus Nginx on Ubuntu?
I reach for Apache when .htaccess-style overrides or module breadth matter, and for teams that already operationalized a2enmod. When I need a hardened reverse proxy in front of app ports, I follow Nginx reverse proxy setup and keep the Ubuntu command snippet next to this tab so reload and firewall commands stay identical.
That sequence installs Apache2, turns on UFW with Apache Full plus SSH, and opens HTTP where AWS expects it. If something still fails, compare the security group, sudo ufw status numbered, and systemctl status apache2 before you assume apt misbehaved. Drop questions in the comments if you get stuck.
Written by Shashikant Dwivedi
Engineer, occasional writer, full-time noticer. Based in Prayagraj, India. New essays land roughly twice a month.
Keep reading
Adjacent essays.
The newsletter
New articles in your inbox.
Occasional articles on engineering, tooling, and software development practices. No marketing, no fluff — just the article, when it's ready.
Unsubscribe with one click. Your email never leaves the list.


