How to Install Apache Web Server on Ubuntu 26.04

Apache is an open-source HTTP web server that supports static and dynamic content delivery through a modular architecture. It functions as a web server, reverse proxy, or load balancer, and integrates with backend processors such as PHP through modules like mod_proxy_fcgi. Apache is one of the most widely deployed web servers for hosting websites, APIs, and web applications.
This article explains how to install the Apache web server on an Ubuntu 26.04 server, configure a virtual host to serve a sample web application, and secure the server with a trusted Let's Encrypt SSL certificate.
Prerequisites
Before you begin, you need to:
- Have access to an Ubuntu 26.04 server instance as a non-root user with sudo privileges.
- Have a domain A record pointing to the server's public IP address. For example,
app.example.com.
Install Apache
The default Ubuntu 26.04 APT repositories include the Apache web server package. The following steps install Apache and verify the installed version.
Update the APT package index.
console$ sudo apt update
Install Apache.
console$ sudo apt install apache2 -y
Confirm the installed Apache version.
console$ apachectl -v
Your output should be similar to the one below:
Server version: Apache/2.4.66 (Ubuntu) Server built: 2026-03-05T17:18:22
Manage the Apache System Service
The apache2 systemd service controls the Apache web server process. The following steps enable automatic startup on boot and demonstrate the core service management commands.
Enable Apache to start automatically at boot time.
console$ sudo systemctl enable apache2
Start the Apache service.
console$ sudo systemctl start apache2
Verify that Apache is active and running.
console$ sudo systemctl status apache2
The output should display
active (running), confirming that the Apache web server is operational.Stop the Apache service.
console$ sudo systemctl stop apache2
Restart the Apache service.
console$ sudo systemctl restart apache2
Set Up Firewall Rules
Uncomplicated Firewall (UFW) is active by default on Ubuntu 26.04. The following steps open ports for HTTP and HTTPS traffic so that Apache can serve web applications.
Allow HTTP traffic on port
80.console$ sudo ufw allow 80/tcp
Allow HTTPS traffic on port
443.console$ sudo ufw allow 443/tcp
Create a Web Root Directory
The web root directory stores the files that Apache serves when a client requests the domain. The following steps create the directory structure and a sample HTML page.
Create the web root directory for the virtual host.
console$ sudo mkdir -p /var/www/app.example.com
Create a sample
index.htmlfile in the web root directory.console$ sudo nano /var/www/app.example.com/index.html
Add the following HTML content to the file.
html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Apache Test Page</title> </head> <body> <h1>Hello World from Apache</h1> </body> </html>
Save and close the file.
Grant the Apache user
www-dataownership of the web root directory.console$ sudo chown -R www-data:www-data /var/www/app.example.com
Create a New Apache Virtual Host
Virtual host configurations direct Apache to serve specific content based on the requested domain name and the corresponding document root directory. The following steps disable the default configuration, create a virtual host for a sample domain, and verify that Apache serves the expected content.
Disable the default Apache virtual host configuration.
console$ sudo a2dissite 000-default.conf
Create a new virtual host configuration file. Replace
app.example.comwith your actual domain.console$ sudo nano /etc/apache2/sites-available/app.example.com.conf
Add the following configuration to the file. Replace
app.example.comwith your actual domain.ini<VirtualHost *:80> ServerAdmin webmaster@app.example.com ServerName app.example.com DocumentRoot /var/www/app.example.com DirectoryIndex index.html index.php <Directory /var/www/app.example.com> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/app.example.com_error.log CustomLog ${APACHE_LOG_DIR}/app.example.com_access.log combined </VirtualHost>
Save and close the file.
Within the configuration:
ServerName: Defines the domain that triggers this virtual host.DocumentRoot: Sets the directory from which Apache serves files.DirectoryIndex: Specifies the default files to serve when the domain is accessed.<Directory>: Defines access permissions for the web root.AllowOverride Allenables.htaccessoverrides.ErrorLogandCustomLog: Store virtual host-specific error and access logs.
Enable the new virtual host configuration.
console$ sudo a2ensite app.example.com.conf
Test the Apache configuration for syntax errors.
console$ sudo apachectl configtest
The output should display
Syntax OK.Restart Apache to activate the virtual host.
console$ sudo systemctl restart apache2
Verify the virtual host by sending a request to the domain using
curl.console$ curl http://app.example.com
A successful response returns the HTML content including the Hello World from Apache heading.
Secure the Apache Web Server
SSL certificates encrypt traffic between a client browser and the Apache web server over HTTPS. The following steps install Certbot and generate a trusted Let's Encrypt SSL certificate to enable HTTPS on your virtual host.
Install the Certbot Let's Encrypt client and the Apache plugin.
console$ sudo apt install certbot python3-certbot-apache -y
Generate an SSL certificate for your domain. Replace
app.example.comwith your actual domain.console$ sudo certbot --apache -d app.example.com --agree-tos
Follow the on-screen prompts to complete the certificate generation. Certbot automatically updates the Apache virtual host configuration to enable HTTPS.
Verify that the automatic renewal process is configured correctly.
console$ sudo certbot renew --dry-run
Access your domain over HTTPS in a web browser to verify the SSL configuration. Replace
app.example.comwith your actual domain.https://app.example.comThe browser displays the Hello World from Apache heading with a valid SSL certificate.
Conclusion
You have installed and configured the Apache web server on an Ubuntu 26.04 server with a virtual host and secured it with a Let's Encrypt SSL certificate. Apache supports multiple virtual hosts and integrates with dynamic content processors such as PHP through modules like mod_proxy_fcgi. For more configuration options, refer to the official Apache documentation.