How to Install Apache Web Server on Ubuntu 26.04

Updated on 24 April, 2026
Install and configure the Apache HTTP web server on an Ubuntu 26.04 for hosting websites with static and dynamic content delivery modules.
How to Install Apache Web Server on Ubuntu 26.04 header image

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:

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.

  1. Update the APT package index.

    console
    $ sudo apt update
    
  2. Install Apache.

    console
    $ sudo apt install apache2 -y
    
  3. 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.

  1. Enable Apache to start automatically at boot time.

    console
    $ sudo systemctl enable apache2
    
  2. Start the Apache service.

    console
    $ sudo systemctl start apache2
    
  3. 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.

  4. Stop the Apache service.

    console
    $ sudo systemctl stop apache2
    
  5. 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.

  1. Allow HTTP traffic on port 80.

    console
    $ sudo ufw allow 80/tcp
    
  2. 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.

  1. Create the web root directory for the virtual host.

    console
    $ sudo mkdir -p /var/www/app.example.com
    
  2. Create a sample index.html file in the web root directory.

    console
    $ sudo nano /var/www/app.example.com/index.html
    
  3. 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.

  4. Grant the Apache user www-data ownership 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.

  1. Disable the default Apache virtual host configuration.

    console
    $ sudo a2dissite 000-default.conf
    
  2. Create a new virtual host configuration file. Replace app.example.com with your actual domain.

    console
    $ sudo nano /etc/apache2/sites-available/app.example.com.conf
    
  3. Add the following configuration to the file. Replace app.example.com with 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 All enables .htaccess overrides.
    • ErrorLog and CustomLog: Store virtual host-specific error and access logs.
  4. Enable the new virtual host configuration.

    console
    $ sudo a2ensite app.example.com.conf
    
  5. Test the Apache configuration for syntax errors.

    console
    $ sudo apachectl configtest
    

    The output should display Syntax OK.

  6. Restart Apache to activate the virtual host.

    console
    $ sudo systemctl restart apache2
    
  7. 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.

  1. Install the Certbot Let's Encrypt client and the Apache plugin.

    console
    $ sudo apt install certbot python3-certbot-apache -y
    
  2. Generate an SSL certificate for your domain. Replace app.example.com with 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.

  3. Verify that the automatic renewal process is configured correctly.

    console
    $ sudo certbot renew --dry-run
    
  4. Access your domain over HTTPS in a web browser to verify the SSL configuration. Replace app.example.com with your actual domain.

    https://app.example.com

    The 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.

Comments