---
title: How to Install Apache Web Server on Ubuntu 22.04
url: https://docs.vultr.com/how-to-install-apache-web-server-on-ubuntu-2204
description: Learn how to install and configure Apache web server on Ubuntu 22.04 with step-by-step instructions for beginners. Get your website up and running quickly.
publish_date: 2025-04-29T11:28:01.149000Z
last_updated: 2025-04-29T12:09:21.230000Z
author: Aashish Chaurasiya
header_image: https://docs.vultr.com/public/doc-assets/2166/3b5a335c-44b2-453b-8538-2bea5dc9af4e.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

Apache is an open-source web server that delivers static and dynamic web applications. It’s highly customizable, supports modular extensions, and can also function as a reverse proxy or load balancer for backend services.

In this article, you are to install Apache web server on Ubuntu 22.04 and deliver web applications securely on your server.

## Prerequisites

Before you begin:

* Have an [Ubuntu 22.04 server](https://www.vultr.com/servers/ubuntu/).

* [Set up a new A record for your domain that points to the server IP address](https://docs.vultr.com/introduction-to-vultr-dns).

* Access the server using SSH as a non-root user with sudo privileges.

* [Update the server](https://docs.vultr.com/how-to-update-a-vultr-cloud-server#how-to-update-debian-&-ubuntu).

## Install Apache

The Apache web server is available in the default repositories for Ubuntu 22.04. Follow the steps below to install the latest version using APT and enable the server to start automatically at boot.

1. Update the server's package index.

    ```console
    $ sudo apt update
    ```

1. Install the Apache web server package.

    ```console
    $ sudo apt install apache2 -y
    ```

1. View the installed Apache web server version.

    ```console
    $ apachectl -v
    ```

    Output:

    ```
    Server version: Apache/2.4.52 (Ubuntu)
    Server built:   2024-03-18T13:41:27
    ```

1. Allow connections on the HTTP port `80`.

    ```console
    $ sudo ufw allow 80/tcp
    ```

1. Access your public server IP using a web browser such as Chrome and verify that the default Apache web page displays.

    ```
    http://SERVER-IP
    ```

## Manage the Apache System Service

Apache is managed by the apache system service, which handles the web server’s runtime processes. Follow the steps below to enable Apache to start at boot and verify its service status.

1. Enable the Apache service to automatically start at boot time.

    ```console
    $ sudo systemctl enable apache2
    ```

    Output:

    ```
    Synchronizing state of apache2.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
    Executing: /usr/lib/systemd/systemd-sysv-install enable apache2
    ```

1. Start the Apache web server.

    ```console
    $ sudo systemctl start apache2
    ```

1. View the service status and verify that it's active on your server.

    ```console
    $ sudo systemctl status apache2
    ```

   Output:

    ```
    ● apache2.service - The Apache HTTP Server
         Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
         Active: active (running) since Sun 2025-04-06 08:30:19 UTC; 4min 16s ago
           Docs: https://httpd.apache.org/docs/2.4/
       Main PID: 2968 (apache2)
          Tasks: 55 (limit: 9385)
         Memory: 5.9M
            CPU: 36ms
         CGroup: /system.slice/apache2.service
                 ├─2968 /usr/sbin/apache2 -k start
                 ├─2969 /usr/sbin/apache2 -k start
                 └─2970 /usr/sbin/apache2 -k start
    ```

1. Stop the Apache web server.

    ```console
    $ sudo systemctl stop apache2
    ```

1. Restart the Apache web server.

    ```console
    $ sudo systemctl restart apache2
    ```

## Create a New Apache Virtual Host

Follow the steps below to disable the default virtual host and create a new virtual host to listen for connection requests using your domain on the default HTTP port `80`.

1. Create a new Apache virtual host configuration file in the `/etc/apache2/sites-available/` directory using a text editor such as `nano`. For example, `website.conf`.

    ```console
    $ sudo nano /etc/apache2/sites-available/website.conf
    ```

1. Add the following contents to the file. Replace `app.example.com` with your domain and `webmaster@example.com` with your web administrator email.

    ```ini
    <VirtualHost *:80>
        ServerAdmin webmaster@example.com
        ServerName app.example.com

        DocumentRoot /var/www/html/website
        DirectoryIndex index.html index.php

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory /var/www/html/website>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    ```

    Save and close the file.

    The above Apache configuration creates a new virtual host that delivers web application files from the `/var/www/html/website` directory using your domain `app.example.com`. Within the configuration:

    * `<VirtualHost *:80>`: Configures the virtual host to listen on HTTP port `80`.
    * `ServerAdmin webmaster@example.com`: Sets the administrator email for error notifications.
    * `ServerName example.com`: Defines the domain for serving the web application. 
    * `DocumentRoot /var/www/html/website`: Specifies the web root directory containing the application files.
    * `DirectoryIndex index.html`: Sets the default file to serve when the domain is accessed.
    * `ErrorLog ${APACHE_LOG_DIR}/error.log`: Specifies the error log file location.
    * `CustomLog ${APACHE_LOG_DIR}/access.log combined`: Defines the access log file using the combined log format.
    * `<Directory /var/www/html/example>`: Applies configurations for requests to the web root directory.
    * `Options Indexes FollowSymLinks`: Enables directory listing and symbolic link following.
        * `AllowOverride All`: Permits `.htaccess` files to override settings.
    * `Require all granted`: Grants access to all users for the web root directory.


1. Disable the default Apache virtual host configuration.

    ```console
    $ sudo a2dissite 000-default
    ```

1. Enable the new Apache virtual host configuration.

    ```console
    $ sudo a2ensite website
    ```

1. Create the web root directory `/var/www/html/website` referenced in your virtual host configuration.

    ```console
    $ sudo mkdir -p /var/www/html/website
    ```

1. Test the Apache configuration for errors.

    ```console
    $ sudo apachectl configtest
    ```

    Output:

    ```
    Syntax OK
    ```

1. Create a new sample HTML application `index.html` file in the web root directory.

    ```console
    $ sudo nano /var/www/html/website/index.html
    ```

1. Add the following contents to the file.

    ```html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Apache Web Server</title>
    </head>
    <body>
        <h1>Greetings from Vultr</h1>
    </body>
    </html>
    ```

    Save and close the file.

1. Grant the web server user and group `www-data` ownership privileges to the `/var/www/html/website` web root directory.

    ```console
    $ sudo chown -R www-data:www-data /var/www/html/website
    ```

1. Restart the Apache web server to apply your configuration changes.

    ```console
    $ sudo systemctl restart apache2
    ```

## Secure the Apache Web Server

Follow the steps below to secure the Apache web server with Let's Encrypt SSL certificates, encrypt network connections, and redirect all HTTP traffic to HTTPS.

1. Install the Certbot Let's Encrypt client package using the Snap package manager.

    ```console
    $ sudo snap install certbot --classic
    ```

1. Request a new Let's Encrypt SSL certificate on your server using your virtual host domain. Replace `app.example.com` with your actual domain and `hello@example.com` with your email address.

    ```console
    $ sudo certbot --apache --agree-tos --redirect -d app.example.com -m hello@example.com
    ```

1. Test the Certbot SSL certificate renewal process.

    ```console
    $ sudo certbot renew --dry-run
    ```

    Output:

1. Restart the Apache web server to apply your SSL configuration changes.

    ```console
    $ sudo systemctl restart apache2
    ```

### Set Up Firewall Rules

Follow the steps below to configure the UFW utility and allow network connections using the Apache web server firewall profile.

1. List all available UFW application profiles.

    ```console
    $ sudo ufw app list
    ```

    Verify that the default Apache profile `apache` is available similar to the following output:

    ```
    Apache
    Apache Full
    Apache Secure
    OpenSSH
    ```

1. Allow the `Apache Full` profile to enable both HTTP port `80` and HTTPS port `443` connections through the firewall.

    ```console
    $ sudo ufw allow 'Apache Full'
    ```

1. Reload UFW to apply the firewall changes.

    ```console
    $ sudo ufw reload
    ```

1. View the firewall status and verify that the new rules are available.

    ```console
    $ sudo ufw status
    ```

    Output:

    ```
    To                         Action      From
    --                         ------      ----
    22/tcp                     ALLOW       Anywhere
    Apache Full                ALLOW       Anywhere
    22/tcp (v6)                ALLOW       Anywhere (v6)
    Apache Full (v6)           ALLOW       Anywhere (v6)
    ```

1. Access your virtual host domain `app.example.com` in a new web browser window and verify that Apache serves your HTML application with a `Greetings from Vultr` message.

    ```
    https://app.example.com
    ```

    ![Apache Virtual Host with a Greetings from Vultr message](https://docs.vultr.com/public/doc-assets/1863/06df7ce5529860f4.png)

## Conclusion

You’ve installed Apache on your Ubuntu 22.04 server. Apache lets you host static websites and integrate with dynamic processors like PHP to serve applications such as WordPress. You can also configure Apache as a reverse proxy using the `mod_proxy` module to securely deliver backend services .For more information and configuration options, visit the [Apache documentation](https://httpd.apache.org/docs/).
