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
2. Install Apache:
$ sudo apt install apache2 -y
3. Verify the installed version:
$ apachectl -v
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
2. Check the service status:
$ sudo systemctl status apache2
3. Stop or restart the service when needed:
$ sudo systemctl stop apache2
$ sudo systemctl restart apache2
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
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
2. Create a sample HTML page:
$ sudo nano /var/www/app.example.com/index.html
<!DOCTYPE html>
<html>
<head><title>My App</title></head>
<body><h1>Hello World from Apache on Ubuntu 26.04</h1></body>
</html>
3. Disable the default site:
$ sudo a2dissite 000-default.conf
4. Create the virtual host configuration:
$ sudo nano /etc/apache2/sites-available/app.example.com.conf
<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>
5. Enable the site, test the configuration, and reload:
$ sudo a2ensite app.example.com.conf
$ sudo apachectl configtest
$ sudo systemctl restart apache2
Verify the virtual host is serving correctly:
$ curl http://app.example.com
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
2. Generate and install the certificate:
$ sudo certbot --apache -d app.example.com --agree-tos
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
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)