DEV Community

Cover image for Installing Apache Web Server on Ubuntu 26.04
Sanskriti Harmukh for Vultr

Posted on • Originally published at docs.vultr.com

Installing Apache Web Server on Ubuntu 26.04

Apache is one of the most widely deployed web servers, with native support in Ubuntu 26.04's default APT repository requiring no external sources. This guide covers the full setup from installation to production readiness, including virtual host configuration for domain-based routing and SSL termination with a free Let's Encrypt certificate backed by automatic renewal.


Install Apache

Apache is available directly from Ubuntu 26.04's default APT repository.

1. Update the APT package index:

$ sudo apt update
Enter fullscreen mode Exit fullscreen mode

2. Install Apache:

$ sudo apt install apache2 -y
Enter fullscreen mode Exit fullscreen mode

3. Verify the installed version:

$ apachectl -v
Enter fullscreen mode Exit fullscreen mode

Manage the Apache Service

Enable Apache as a systemd service so it starts automatically on every boot.

1. Enable and start the service:

$ sudo systemctl enable apache2
$ sudo systemctl start apache2
Enter fullscreen mode Exit fullscreen mode

2. Check the service status:

$ sudo systemctl status apache2
Enter fullscreen mode Exit fullscreen mode

3. Stop or restart the service when needed:

$ sudo systemctl stop apache2
$ sudo systemctl restart apache2
Enter fullscreen mode Exit fullscreen mode

Configure Firewall Rules

Open ports 80 and 443 to allow HTTP and HTTPS traffic through the firewall.

$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp
Enter fullscreen mode Exit fullscreen mode

Open http://YOUR-SERVER-IP in a browser. The Apache default page confirms the service is running.


Create a Virtual Host

Virtual hosts allow Apache to serve multiple domains from the same server. Replace app.example.com with your actual domain throughout this section.

1. Create the web root directory:

$ sudo mkdir -p /var/www/app.example.com
$ sudo chown -R www-data:www-data /var/www/app.example.com
Enter fullscreen mode Exit fullscreen mode

2. Create a sample HTML page:

$ sudo nano /var/www/app.example.com/index.html
Enter fullscreen mode Exit fullscreen mode
<!DOCTYPE html>
<html>
<head><title>My App</title></head>
<body><h1>Hello World from Apache on Ubuntu 26.04</h1></body>
</html>
Enter fullscreen mode Exit fullscreen mode

3. Disable the default site:

$ sudo a2dissite 000-default.conf
Enter fullscreen mode Exit fullscreen mode

4. Create the virtual host configuration:

$ sudo nano /etc/apache2/sites-available/app.example.com.conf
Enter fullscreen mode Exit fullscreen mode
<VirtualHost *:80>
    ServerName app.example.com
    DocumentRoot /var/www/app.example.com
    <Directory /var/www/app.example.com>
        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>
Enter fullscreen mode Exit fullscreen mode

5. Enable the site, test the configuration, and reload:

$ sudo a2ensite app.example.com.conf
$ sudo apachectl configtest
$ sudo systemctl restart apache2
Enter fullscreen mode Exit fullscreen mode

Verify the virtual host is serving correctly:

$ curl http://app.example.com
Enter fullscreen mode Exit fullscreen mode

Secure with Let's Encrypt SSL

Certbot automates certificate issuance and renewal through Let's Encrypt, with an Apache plugin that handles virtual host configuration directly.

1. Install Certbot with the Apache plugin:

$ sudo apt install certbot python3-certbot-apache -y
Enter fullscreen mode Exit fullscreen mode

2. Generate and install the certificate:

$ sudo certbot --apache -d app.example.com --agree-tos
Enter fullscreen mode Exit fullscreen mode

Certbot obtains the certificate, updates the virtual host to enable HTTPS, and configures an HTTP-to-HTTPS redirect automatically.

3. Test the auto-renewal timer:

$ sudo certbot renew --dry-run
Enter fullscreen mode Exit fullscreen mode

A dry run without errors confirms automatic renewal is configured correctly.


Next Steps

Apache is now running and serving your domain over HTTPS. From here you can:

  • Add PHP via PHP-FPM to serve dynamic content alongside Apache
  • Configure Apache as a reverse proxy in front of a Node.js or Python application
  • Enable HTTP/2 support with sudo a2enmod http2

For the complete guide, visit the original article on Vultr Docs.

Top comments (0)