Skip to content
DevOps devops webservers 6 min read

Installing Apache on Ubuntu

Apache HTTP Server (often just called “Apache”) is one of the oldest and most widely used web servers in the world. A web server is a program that listens for incoming HTTP requests (the messages your browser sends when it asks for a web page) and sends back the right files or responses. In this guide you will install Apache on Ubuntu from scratch, start it, open the firewall, and confirm it works by loading its default welcome page in a browser. Getting this right is the foundation for everything else: hosting websites, running virtual hosts, and using Apache as a reverse proxy later on.

A quick note on the name: apache2

On Ubuntu (and other Debian-based Linux systems), the Apache package and its background service are not called apache. They are called apache2. This trips up a lot of beginners. So the package you install is apache2, the service you start with systemd (Ubuntu’s system that starts and supervises background programs) is apache2, and the config lives in /etc/apache2. On Red Hat-based systems (like CentOS or Fedora) the same software is instead called httpd — but this page targets Ubuntu, so we use apache2 everywhere.

When to use Apache (and when not to)

Apache is a mature, flexible web server. Use it when you want per-directory configuration via .htaccess files, a huge ecosystem of modules, or when software you are installing (like older PHP apps or shared hosting setups) expects Apache. Reach for Nginx instead when you mainly need a fast static-file server or a lightweight reverse proxy under heavy traffic. Many real setups run both — Nginx out front, Apache behind it.

Update your package list first

Before installing anything on Ubuntu, refresh the local list of available packages so apt (Ubuntu’s package manager — the tool that downloads and installs software) knows about the latest versions.

sudo apt update

sudo runs the command as the administrator (root), which you need to install system software.

Install Apache

Now install the apache2 package.

sudo apt install apache2 -y

The -y flag automatically answers “yes” to the confirmation prompt so the install runs unattended.

Output:

Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils
...
Setting up apache2 (2.4.58-1ubuntu1) ...
Enabling module mpm_event.
Enabling module authz_core.
...
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /usr/lib/systemd/system/apache2.service.

Notice that Ubuntu automatically enables and starts the apache2 service for you right after install.

Verify the service is running

Use systemctl, the command-line tool for controlling systemd services, to check Apache’s status.

sudo systemctl status apache2

Output:

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
     Active: active (running) since Mon 2026-06-15 10:21:04 UTC; 30s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 1842 (apache2)
      Tasks: 55 (limit: 2275)
     Memory: 6.0M
        CPU: 41ms
     CGroup: /system.slice/apache2.service
             ├─1842 /usr/sbin/apache2 -k start
             ├─1845 /usr/sbin/apache2 -k start
             └─1846 /usr/sbin/apache2 -k start

The two words to look for are active (running) (Apache is up) and enabled (it will start automatically on every boot). If for some reason it is not running, start it and enable it manually:

sudo systemctl start apache2
sudo systemctl enable apache2

Here are the everyday systemctl commands you will use with Apache:

CommandWhat it doesWhen to use it
sudo systemctl start apache2Starts the server nowAfter it was stopped
sudo systemctl stop apache2Stops the server nowMaintenance, freeing port 80
sudo systemctl restart apache2Stops then startsAfter a config change
sudo systemctl reload apache2Reloads config without dropping connectionsSafer than restart for live sites
sudo systemctl enable apache2Auto-start on bootOne-time setup
sudo systemctl status apache2Show current stateTroubleshooting

Tip: Prefer reload over restart on a live server. reload re-reads the configuration without killing active connections, so visitors mid-request are not disconnected. Always run sudo apache2ctl configtest before reloading to catch syntax errors first.

Open the firewall

Ubuntu ships with UFW (Uncomplicated Firewall — a simple front-end for managing firewall rules). If UFW is active, it blocks Apache’s traffic until you explicitly allow it. Apache registers handy named profiles with UFW during install. List them:

sudo ufw app list

Output:

Available applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH

Here is what each profile opens:

ProfilePorts openedUse it when
Apache80 (HTTP)Plain HTTP only
Apache Secure443 (HTTPS)HTTPS only
Apache Full80 and 443Most real sites (HTTP + HTTPS)

Allow Apache Full so both plain and encrypted traffic can reach the server:

sudo ufw allow 'Apache Full'
sudo ufw reload

Confirm the rule was added:

sudo ufw status

Output:

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Apache Full                ALLOW       Anywhere

Warning: Always allow OpenSSH (port 22) before enabling UFW on a remote server. If you enable the firewall without an SSH rule, you will lock yourself out of the machine.

Load the default page

Find your server’s IP address so you know what to type in the browser:

hostname -I

Output:

203.0.113.42 10.0.0.5

Open the first (public) address in a browser: http://203.0.113.42. You should see the “Apache2 Ubuntu Default Page” with the big “It works!” banner. That page is a real HTML file living at /var/www/html/index.html, served from Apache’s default document root (/var/www/html — the folder Apache serves files from). You can also test from the command line:

curl -I http://localhost

Output:

HTTP/1.1 200 OK
Date: Mon, 15 Jun 2026 10:25:11 GMT
Server: Apache/2.4.58 (Ubuntu)
Content-Type: text/html; charset=UTF-8

HTTP/1.1 200 OK means success, and Server: Apache/2.4.58 (Ubuntu) confirms Apache is answering.

Watch out for a port conflict with Nginx

Both Apache and Nginx default to listening on port 80 (the standard HTTP port). Only one program can hold a given port at a time. So if you already have Nginx installed and running, apache2 will fail to start with an “Address already in use” error.

sudo ss -ltnp | grep ':80 '

Output:

LISTEN 0  511  0.0.0.0:80  0.0.0.0:*  users:(("nginx",pid=901,fd=6))

If you see nginx here, decide which server should own port 80. To stop Nginx and let Apache take over:

sudo systemctl stop nginx
sudo systemctl disable nginx
sudo systemctl restart apache2

If you want to run both on the same box, they cannot both use port 80 directly — change one server’s listen port, or put Nginx in front of Apache as a reverse proxy (a server that sits in front of another and forwards requests to it). See the related topics below for that pattern.

Best practices

  • Run sudo apache2ctl configtest after every config change and before any reload or restart.
  • Use sudo systemctl reload apache2 instead of restart on production to avoid dropping live connections.
  • Keep Apache patched: run sudo apt update && sudo apt upgrade regularly, since web servers are exposed to the internet.
  • Open only the ports you need with UFW (Apache Full for HTTP+HTTPS), and never enable the firewall without an SSH rule first.
  • Check /var/log/apache2/error.log first whenever Apache misbehaves — most problems are explained there.
  • Before installing, verify nothing else owns port 80 with sudo ss -ltnp | grep ':80 ' to avoid silent startup failures.
Last updated June 15, 2026
Was this helpful?