NewHalo Edge 3 is here: HTTP/3 everywhere and 42 edge locations.Learn more
Docs / Web servers

Install and configure Apache

Web servers7 min readUbuntu 24.04 LTS

Apache HTTP Server is one of the most widely used web servers, with decades of documentation and a large library of modules. This guide installs it on Ubuntu 24.04, opens the firewall, and serves a test page. Apache and nginx both want port 80, so run only one of them on a given server unless you configure them carefully.

Before you begin

  • A VPS running Ubuntu 24.04 LTS, with SSH access as root or as a sudo user, such as deploy.
  • The server's IP address. This guide uses 203.0.113.10 as an example.
  • Nothing else listening on port 80. If you followed the nginx guide, stop nginx first with sudo systemctl stop nginx and sudo systemctl disable nginx.

Step 1: Update the package lists

Refresh the package list and install any pending updates. This makes sure you get current versions of the software. If you are logged in as root, leave out sudo.

sudo apt update
sudo apt upgrade -y

Step 2: Install Apache

On Ubuntu the package is called apache2. The -y flag answers the install prompt for you.

sudo apt install -y apache2

Step 3: Check that Apache is running

Ubuntu starts Apache after installation. Ask systemd, the service manager, for its status. The version check confirms which build you installed.

systemctl status apache2 --no-pager
apache2 -v
     Active: active (running) since Thu 2026-10-29 09:20:11 UTC; 2min ago
Server version: Apache/2.4.58 (Ubuntu)

Step 4: Open the firewall

The UFW firewall blocks incoming traffic by default. Allow SSH first, then allow the Apache Full profile, which opens port 80 for HTTP and port 443 for HTTPS. Enable the firewall, then check the rules.

sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
sudo ufw enable
sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Apache Full                ALLOW       Anywhere
Careful: Allow OpenSSH before you enable UFW. If you skip this, the firewall can cut off your SSH connection.

Step 5: View the default page

Ask Apache for its page with curl. The -I option requests only the response headers, so you can see the status code quickly.

curl -I http://localhost
HTTP/1.1 200 OK
Server: Apache/2.4.58 (Ubuntu)

Open http://203.0.113.10 in your browser. You should see the "Apache2 Ubuntu Default Page."

Step 6: Replace the test page

Apache serves files from /var/www/html by default. The tee command writes your HTML into that file with the permissions sudo provides.

echo "<h1>Hello from Apache</h1>" | sudo tee /var/www/html/index.html
curl http://localhost
<h1>Hello from Apache</h1>

Step 7: Test the configuration after every change

The main configuration file is /etc/apache2/apache2.conf. Site definitions live in /etc/apache2/sites-available/. After editing any of them, check the syntax and then reload Apache.

sudo apache2ctl configtest
sudo systemctl reload apache2
Syntax OK
Tip: apache2ctl is the control tool for Apache. Its configtest option is the safest way to check your work before a reload.

Troubleshooting

  • Apache fails to start with a port 80 error. nginx or another service is using the port. Check with sudo ss -tlnp | grep :80 and stop the conflicting service.
  • configtest reports an error. The message names the file and line number. Fix that line, then run configtest again.
  • The browser shows the old page. Try a private window, or reload with Ctrl+Shift+R. Confirm the file contents with cat /var/www/html/index.html.
  • The browser cannot connect. Run sudo ufw status and confirm the Apache Full rule is listed.

Next steps

Once Apache responds, add a domain with Host multiple sites with Apache virtual hosts, and then add HTTPS with Enable HTTPS with free TLS certificates.

Something not working? Chat or email our support team and we will help you get unstuck.

Contact support