Knowing how to install and configure Apache on Ubuntu 26.04 is essential for anyone looking to host websites or web applications on a Linux server. Apache HTTP Server remains one of the most widely deployed web servers in the world, and Ubuntu 26.04 Resolute Raccoon provides a stable foundation for running it. In this tutorial, you will learn how to install Apache, set up virtual hosts, enable URL rewriting with mod_rewrite, configure SSL encryption, and apply basic security hardening to your server.
Software Requirements and Linux Command Line Conventions
Category
Requirements, Conventions or Software Version Used
System
Ubuntu 26.04 Resolute Raccoon
Software
Apache HTTP Server (apache2)
Other
Privileged access to your Linux system as root or via the sudo command.
Conventions
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user
Install Apache on Ubuntu 26.04 with apt, then configure virtual hosts and enable SSL.
The Apache HTTP Server is available directly from the Ubuntu 26.04 default repositories. Therefore, installation is straightforward using the apt package manager. Begin by updating your package index and installing the apache2 package.
Update the package index and install Apache:
$ sudo apt update
$ sudo apt install apache2
This installs the Apache web server along with all required dependencies.
Verify that the Apache service is running:
$ sudo systemctl status apache2
You should see active (running) in the output. Apache starts automatically after installation on Ubuntu 26.04.
Allow HTTP traffic through the firewall: If you have UFW enabled, you need to allow port 80 with UFW for Apache to serve web pages:
$ sudo ufw allow 'Apache'
This opens port 80 (HTTP). To additionally allow HTTPS traffic on port 443:
$ sudo ufw allow 'Apache Full'
Test the default Apache page: Open a web browser and navigate to your server’s IP address. You can find your server’s IP with:
$ hostname -I
Enter http://your_server_ip in the browser. You should see the Apache2 Ubuntu Default Page confirming that the web server is working correctly.
Virtual hosts allow you to host multiple websites on a single Apache server. Each virtual host has its own configuration file that defines the domain name, document root, and other settings. Consequently, this is one of the most important aspects of Apache configuration on Ubuntu 26.04.
Create a document root directory for your website:
$ sudo mkdir -p /var/www/linuxconfig.org/html
Set appropriate ownership so that the regular user can manage files:
The ServerName directive defines the primary domain, while ServerAlias handles alternative domain names. The DocumentRoot points to the directory containing your website files.
Enable the new virtual host and disable the default site:
The configtest command checks for syntax errors before applying changes. You should see Syntax OK in the output.
TROUBLESHOOTING
If you see the warning AH00558: apache2: Could not reliably determine the server's fully qualified domain name when running configtest or restarting Apache, set the ServerName directive globally:
The mod_rewrite module allows you to create clean, SEO-friendly URLs by rewriting requests on the server side. Many web applications, including WordPress and Laravel, require this module. To enable mod_rewrite on Ubuntu 26.04, follow these steps.
Enable the rewrite module:
$ sudo a2enmod rewrite
Update your virtual host to allow .htaccess overrides: Edit the virtual host configuration file:
The AllowOverride All directive permits .htaccess files to override server configuration within that directory. Additionally, Options -Indexes disables directory listing while +FollowSymLinks allows symbolic links.
Restart Apache to apply changes:
$ sudo systemctl restart apache2
Verify that mod_rewrite is active:
$ sudo apache2ctl -M | grep rewrite
You should see rewrite_module (shared) in the output, confirming the module is loaded.
Enabling SSL encryption protects data transmitted between your server and visitors. While production environments should use certificates from a trusted Certificate Authority such as Let’s Encrypt, a self-signed certificate is useful for testing and internal environments. Here is how to configure SSL on Apache with Ubuntu 26.04.
You will be prompted to enter certificate information. The most important field is Common Name, which should match your domain name or server IP address.
IMPORTANT
A self-signed certificate will trigger a browser security warning because it is not issued by a trusted Certificate Authority. For production websites, use a free certificate from Let’s Encrypt or a commercial CA instead.
IMPORTANT
The browser displays “Not secure” because the self-signed certificate is not issued by a trusted Certificate Authority. This is expected behavior and does not mean your SSL encryption is broken. The connection is still encrypted, but the browser cannot verify the server’s identity. For production websites, replace the self-signed certificate with one from a trusted CA such as Let’s Encrypt.
Basic Apache Security Hardening
After installing Apache on Ubuntu 26.04, it is important to apply some basic security measures. By default, Apache exposes version information and other details that attackers can exploit. The following steps help reduce your server’s attack surface.
Hide Apache version and OS information: Edit the security configuration file:
ServerTokens Prod makes Apache report only “Apache” in the Server header without version numbers. ServerSignature Off removes the server information from error pages.
Disable directory listing globally: In the same file, ensure the following option is set:
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Enable the headers module and the new configuration:
SECURITY TIP
These are baseline security measures. For production servers, consider additional hardening such as configuring mod_security as a web application firewall, disabling unnecessary modules, and implementing rate limiting. Refer to the official Apache security tips for comprehensive guidance.
Manage Apache Service
Ubuntu 26.04 uses systemctl to manage the Apache service. Understanding these commands is essential for day-to-day server administration. Moreover, knowing where to find logs helps you troubleshoot issues quickly.
Use restart when making changes that require a full service restart. For configuration changes that do not require dropping active connections, use reload instead:
$ sudo systemctl reload apache2
IMPORTANT
If you see a warning such as The unit file, source configuration file or drop-ins of apache2.service changed on disk, run sudo systemctl daemon-reload first, then retry the reload:
If you configured custom log paths in your virtual host, check those locations instead. For example, the virtual host created earlier logs to linuxconfig_error.log and linuxconfig_access.log in the same directory.
List enabled modules and sites: To see which modules and virtual hosts are currently active:
$ sudo apache2ctl -M
$ ls /etc/apache2/sites-enabled/
If you need to open additional firewall ports for other services running alongside Apache, make sure to configure UFW accordingly.
Conclusion
In this tutorial, you learned how to install and configure Apache on Ubuntu 26.04 from start to finish. You set up the web server, created virtual hosts to serve multiple websites, enabled mod_rewrite for clean URLs, configured SSL encryption with a self-signed certificate, and applied basic security hardening. Apache is now ready to serve your websites and web applications on Ubuntu 26.04 Resolute Raccoon.
Frequently Asked Questions
How do I check which version of Apache is installed on Ubuntu 26.04? Run apache2 -v in the terminal. This displays the Apache version number and the build date. You can also use sudo apt show apache2 for more detailed package information.
What is the difference between restart and reload in Apache? The restart command completely stops and starts the Apache service, dropping all active connections. The reload command gracefully applies configuration changes without interrupting existing connections. Use reload whenever possible to avoid downtime.
Can I host multiple websites on a single Apache server? Yes, Apache virtual hosts allow you to serve multiple websites from one server. Each site gets its own configuration file in /etc/apache2/sites-available/ with a unique ServerName. Enable each site with a2ensite and ensure DNS records point to your server’s IP address.
How do I get a free SSL certificate for Apache instead of a self-signed one? Use Let’s Encrypt with the Certbot tool. Install Certbot with sudo apt install certbot python3-certbot-apache, then run sudo certbot --apache to automatically obtain and configure a trusted certificate at no cost.