How to Install Apache Web Server on Ubuntu 24.04
Learn how to install apache on ubuntu 24.04 LTS with UFW firewall configuration, virtual hosts, directory permissions, and service management.

5 min read
Learn how to install apache on ubuntu 24.04 LTS with UFW firewall configuration, virtual hosts, directory permissions, and service management.
- Prerequisites and Supported Releases
- Step 1: Updating Package Repositories and Installing Apache
- Step 2: Adjusting UFW Firewall for Web Traffic
The Apache HTTP Server—commonly referred to simply as Apache—is one of the most resilient, adaptable, and widely deployed open-source web servers in internet history.
Powering millions of websites globally, Apache delivers a robust modular architecture, dynamic content handling, extensive authentication modules, and granular per-directory configuration via .htaccess files.
Ubuntu 24.04 LTS (Noble Numbat) packages Apache 2.4 directly within its core repositories, ensuring turnkey integration with the operating system's security features and systemd init ecosystem.
In this comprehensive guide, we demonstrate how to install apache on ubuntu 24.04 from base repository installation to creating custom Virtual Hosts, managing firewall profiles, and troubleshooting common runtime errors.
Comprehensive step-by-step administrator and web developer guide on how to install and configure the Apache HTTP web server on Ubuntu 24.04 LTS (Noble Numbat). Covers package installation from official APT repositories, UFW firewall adjustments, basic service management with systemctl, setting up custom Apache Virtual Hosts, configuring file permissions, and verifying live web responses.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A server or virtual machine running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
- A non-root user account with
sudoadministrative privileges. - A configured UFW (Uncomplicated Firewall) running on your server.
- An optional registered domain name pointing to your public server IP address.
Step 1: Updating Package Repositories and Installing Apache
Before installing any new software, update your local APT repository cache to guarantee access to the latest packages and security patches.
Once updated, install the apache2 meta-package using the APT package manager:
APT downloads Apache along with essential runtime dependencies, including the APR (Apache Portable Runtime) utilities and default configuration templates:
# Update repository cache and install Apache HTTP server:
sudo apt update
sudo apt install -y apache2
# Check the installed version of Apache:
apache2 -v
# Expected output confirms:
# Server version: Apache/2.4.58 (Ubuntu)
# Server built: 2024-04-18T15:13:41
Step 2: Adjusting UFW Firewall for Web Traffic
Ubuntu systems utilizing UFW must permit incoming web traffic on port 80 (HTTP) and port 443 (HTTPS).
Apache registers pre-configured application profiles with UFW during installation:
We recommend enabling the Apache Full profile, which opens both unencrypted port 80 and TLS-encrypted port 443:
Verify that the firewall rules have taken effect by checking the UFW status:
# List available UFW application profiles:
sudo ufw app list
# Profiles: 'Apache', 'Apache Full', 'Apache Secure'
# Allow both HTTP (80) and HTTPS (443):
sudo ufw allow 'Apache Full'
# Verify UFW status and active rules:
sudo ufw status
# Status: active
# Action: ALLOW
# From: Anywhere for Apache Full
Step 3: Checking the Apache Web Server Service Status
On Ubuntu 24.04, systemd initializes and enables the Apache service automatically upon package installation.
Verify that the web server daemon is active and running without errors:
You can also query the web server locally using curl to confirm that it serves the default landing page:
# Verify systemd service status:
sudo systemctl status apache2
# Output confirms: Active: active (running)
# Test HTTP response locally via loopback:
curl -I http://localhost
# Expected output confirms:
# HTTP/1.1 200 OK
# Server: Apache/2.4.58 (Ubuntu)
# Content-Type: text/html
Step 4: Managing the Apache Process with systemctl
System administrators frequently need to stop, start, reload, or restart the Apache web server daemon during maintenance or configuration updates.
Use standard systemctl commands to govern the Apache process lifecycle:
Reloading is preferred over restarting when updating configuration files because reloading does not drop active client connections:
# Stop the Apache web server:
sudo systemctl stop apache2
# Start the Apache web server:
sudo systemctl start apache2
# Restart Apache (terminates and restarts worker processes):
sudo systemctl restart apache2
# Reload configuration without dropping active client connections:
sudo systemctl reload apache2
# Disable Apache from starting automatically on system boot:
sudo systemctl disable apache2
# Enable Apache to start automatically on system boot:
sudo systemctl enable apache2
Step 5: Setting Up an Apache Virtual Host
While the default Apache configuration serves content from /var/www/html, modern web servers host multiple domains using Virtual Hosts.
Create a dedicated document root for your domain, such as example.com, and assign appropriate directory permissions:
Next, create a simple HTML test page inside your custom website root directory:
# Create document root directory structure:
sudo mkdir -p /var/www/example.com/public_html
# Assign directory ownership to your non-root user:
sudo chown -R $USER:$USER /var/www/example.com/public_html
# Ensure proper read and execute permissions for web visitors:
sudo chmod -R 755 /var/www/example.com
# Create a test landing page:
cat << 'EOF' > /var/www/example.com/public_html/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome to Example.com</title>
</head>
<body>
<h1>Success! The example.com virtual host is working on Ubuntu 24.04!</h1>
</body>
</html>
EOF
Creating the Virtual Host Configuration File
Apache stores available virtual host configurations in /etc/apache2/sites-available/.
Create a new configuration file for your custom domain using your preferred text editor:
Add the following VirtualHost directives, replacing example.com with your domain name:
# /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>
Enabling the Virtual Host and Testing Syntax
Enable the new site configuration using the a2ensite helper script.
Always test Apache configuration syntax with apache2ctl configtest before reloading the server to prevent downtime:
Once confirmed, reload Apache to activate the virtual host:
# Enable the custom virtual host:
sudo a2ensite example.com.conf
# Optionally disable the default 000-default site if not needed:
sudo a2dissite 000-default.conf
# Validate Apache syntax configuration:
sudo apache2ctl configtest
# Expected output confirms: Syntax OK
# Reload Apache service:
sudo systemctl reload apache2
Step 6: Securing Apache with Free Let's Encrypt SSL Certificates
Transport Layer Security (TLS/SSL) encryption is an absolute requirement for all modern production websites.
Install the Certbot client alongside the official Apache Certbot plugin via APT:
Execute the Certbot interactive utility to automatically obtain a trusted certificate and update your Apache virtual host with HTTPS redirection:
# Install Certbot and Apache plugin:
sudo apt install -y certbot python3-certbot-apache
# Request certificate and configure Apache HTTPS redirect:
sudo certbot --apache -d example.com -d www.example.com
# Verify automated renewal dry-run:
sudo certbot renew --dry-run
# Output confirms: Congratulations, all simulated renewals succeeded.
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name
Cause: Apache lacks a global ServerName directive in its main configuration file.
Resolution: Add ServerName 127.0.0.1 to /etc/apache2/conf-available/servername.conf and enable it.
echo 'ServerName 127.0.0.1' | sudo tee /etc/apache2/conf-available/servername.conf && sudo a2enconf servername && sudo systemctl reload apache2
403 Forbidden error when visiting custom domain
Cause: Incorrect directory permissions on /var/www/ or missing Require all granted in Virtual Host.
Resolution: Set directory permissions to 755 and verify Directory block in the VirtualHost file.
sudo chmod -R 755 /var/www/example.com && sudo apache2ctl configtest
Port 80 address already in use (bind: Address already in use)
Cause: Another web server daemon (such as Nginx, Caddy, or Lighttpd) is already bound to port 80.
Resolution: Identify and stop the conflicting service using ss or lsof.
sudo ss -tulpn | grep :80
Security Best Practices and Hardening
Disable directory browsing globally by setting Options -Indexes inside your virtual host configuration to avoid exposing file structures.
Hide server version and operating system details by setting ServerTokens Prod and ServerSignature Off in /etc/apache2/conf-available/security.conf.
Enable the Apache HTTP security headers module (sudo a2enmod headers) to enforce HSTS, X-Content-Type-Options, and X-Frame-Options.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Install LAMP Stack on Ubuntu 24.04 — Combine Apache with MySQL and PHP 8.3 for dynamic web hosting.
- How to Set Up a Firewall with UFW on Ubuntu 24.04 — Master firewall rules, logging, and port policies on Ubuntu.
- Initial Server Setup on Ubuntu 24.04 LTS — Configure non-root users, SSH security, and system updates.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
/etc/apache2/apache2.conf. Additional modular configurations, modules, and virtual host files reside in /etc/apache2/sites-available/, /etc/apache2/mods-available/, and /etc/apache2/conf-available/./var/log/apache2/access.log and diagnostic failure events to /var/log/apache2/error.log.sudo apache2ctl configtest. If the configuration is valid, the command returns Syntax OK.sudo a2enmod rewrite followed by sudo systemctl restart apache2 to enable rewrite rules for friendly URLs.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides
Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!