Apache, also known as Apache HTTP server, has been one of the most widely used web server applications globally for the past few decades. By default, Apache is available on Ubuntu 20.04 repository; however, with Ubuntu LTS releases, stable versions do not change for the most part except for security or urgent bug updates to keep the title “stable,” for which they are known. Due to this, Apache can miss out on new features and improvements and non-security-related bug fixes especially given the time delay between long-term releases being a few years in between.
In the following tutorial, you will learn how to Upgrade to the latest Apache web server on Ubuntu 20.04 LTS Focal Fossa desktop or server using the custom third-party repository by Ondrey Sury is most known for his PHP maintainer work Debian/Ubuntu.
Table of Contents
First, ensure your system is up-to-date by running the following command before proceeding to avoid any conflicts.
sudo apt update && sudo apt upgrade
Install Latest Apache
Adding Apache Repository by Ondřej Surý Repository
The first step is to import and install the Apache webserver to the latest version is add the repository by Ondřej Surý.
Add the PPA with the following command in your terminal.
sudo add-apt-repository ppa:ondrej/apache2 -y
Update your repository to reflect the new change.
sudo apt update
Now that you have installed the PPA and updated the repository list, install Apache2 with the following.
sudo apt install apache2 -y
Now, make sure Apache is running by using the systemctl command.
systemctl status apache2
If no errors exist, you have successfully upgraded your Apache version using the PPA.
To start the webserver application, users that see the status as inactive and Apache is not activated use the following command.
sudo systemctl start apache2
To enable Apache on system boot, use the following.
sudo systemctl enable apache2
This version will always be maintained and updated when a new version of Apache is available; Ondřej Surý updates typically within a few days to a few weeks as he maintains PHP, Nginx, and Apache repositories built; he is consistent with his updating.
Optional. Configure UFW Firewall for Apache
After installing Apache 2 web server, you will need to modify the UFW rules if you have UFW installed. To allow outside access to the default web ports. Luckily, during the installation, Apache registers itself with UFW to provide a few profiles that can be used to enable or disable access, making it easy and quick to configure.
If you would like to install the UFW firewall, run the following command.
sudo apt install ufw -y
Once UFW is installed, enable UFW to start and be active on system boot.
sudo ufw enable
Next, list the application profiles to see the Apache profiles that are available by the following command:
sudo ufw app list
Available applications: Apache Apache Full Apache Secure
From the output above, you have three profile options to choose from. To break it down, Apache runs on port 80 (HTTP), Apache Secure runs on port 443 (HTTPS), and Apache Full is a combination of allowing both. The most common is either Apache Full or Apache Secure.
For the tutorial, since we have not set up SSL, we will enable (Apache) profile with the following command:
sudo ufw allow 'Apache'
Rule added Rule added (v6)
As above, the rules have been added for both IPV4 and IPV6. Later on, you can disable this profile and enable secure only or disable the Apache rule and use the Apache Full rule instead.
How to Update Apache
Given that Apache was installed and upgraded with the APT package manager, run the standard APT update commands.
sudo apt update
If one is available, upgrade Apache as follows:
sudo apt upgrade
Or upgrade Apache by itself:
sudo apt upgrade apache2
That is all you need to do to keep your version updated.
How to Remove (Uninstall) Apache Upgrade
First, stop the service for users who want to restore the standard Ubuntu version.
sudo systemctl stop apache2
Now remove Apache with the following command.
sudo apt autoremove apache2
Now, remove the imported PPA if you plan on returning to the default version from Ubuntu’s repository.
sudo add-apt-repository --remove ppa:ondrej/apache2 -y
Lastly, run an APT update to reflect the changes to the APT sources list entries.
sudo apt-get update
From here, you can now re-install the standard Apache version.
Comments and Conclusion
Overall, Apache has been the most used web application server for decades. However, Nginx has finally overtaken the lead just slightly. Apache is still one of the most deployed and recognized web applications, especially with combing LAMP stack, which is often used for back-end web servers. You will find more friendly options for Apache than Nginx, leading newer users to get into hosting their web server, perhaps to try Apache over Nginx as the first step.