Guides 11792 Published by

The passage provides a concise, step‑by‑step tutorial for installing and verifying Apache 2 on Ubuntu 20.04, including updating package lists, installing the apache2 package, and checking that the service is running via systemctl. It also advises optional security hardening with ufw (opening ports 80/443) and shows how to test the default “It works!” page, adjust the DocumentRoot, and reload configurations safely. Additionally, it mentions common troubleshooting tips—such as reinstalling Apache if modules fail—and cautions that for simple static serving a lightweight Python server may be preferable. Overall, the guide equips users with everything needed to get a functional Apache web server up and running while highlighting best practices and potential pitfalls.



How to Install Apache Web Server on Ubuntu 20.04

You’ll get a working Apache HTTP server up and running on Ubuntu 20.04 without wading through endless docs. The steps below cover the basics, point out common pitfalls, and give you a quick sanity‑check that the service is really serving pages.

What you need before you start

  • A fresh or already provisioned Ubuntu 20.04 installation (Desktop or Server).
  • An account with sudo privileges.
  • Internet access so apt can pull packages from the official repositories.

If you’re running a minimal cloud image, you’ll probably notice that ufw isn’t even installed yet – that’s fine, we’ll add it later if you want a firewall.

Install Apache with apt

sudo apt update
sudo apt install apache2 -y

apt update refreshes the package index; without it you might end up with an older 2.4.x build that lacks recent security fixes. The -y flag just skips the confirmation prompt, which is handy when you’re scripting the setup.

Make sure Apache actually starts

sudo systemctl status apache2

You should see “active (running)” in green. If it’s stuck at “failed”, check the journal:

sudo journalctl -u apache2 --no-pager | tail -n 20

I’ve seen this happen after a rogue driver update that left the mod_ssl module dangling – reinstalling the package (sudo apt install --reinstall apache2) usually clears it up.

Enable the firewall (optional but recommended)

Ubuntu ships with ufw disabled by default. Opening port 80 and 443 is as simple as:

sudo ufw allow 'Apache Full'
sudo ufw enable

If you only need plain HTTP, replace 'Apache Full' with 'Apache'. Skipping this step on a public server is basically inviting trouble.

Test the default page

Open a browser and point it at http://your_server_ip/. You should see the familiar “It works!” Apache splash page. If you get a 404 or nothing loads, double‑check that your network interface isn’t blocked by a cloud provider’s security group.

Quick config tweaks (optional)

The default virtual host serves files from /var/www/html. For a personal project you might want to point it elsewhere:

sudo nano /etc/apache2/sites-available/000-default.conf

Change the DocumentRoot line, save, then reload Apache:

sudo systemctl reload apache2

Remember: every time you touch a config file, run apachectl configtest first. It will warn you about syntax errors before you break the live site.

When Apache is overkill

If you only need to serve static files for a quick demo, firing up Python’s built‑in server (python3 -m http.server 8080) beats installing Apache by miles. Save yourself the maintenance overhead unless you actually need modules like mod_rewrite or SSL termination.

That’s it – you now have a functional Apache web server on Ubuntu 20.04. Feel free to experiment with virtual hosts, Let's Encrypt certificates, or whatever else your project demands.