Apache, also known as Apache HTTP server, has been one of the most widely used web server applications globally for the past few decades. Apache comes on Ubuntu 20.04 default repository; however, most LTS repositories are often not updated to the latest version compared to what is current from the developer. In this case, Apache can miss out on new features and improvements and non-security-related bug fixes.
In the following tutorial, you will learn how to Upgrade the Apache webserver on Ubuntu 20.04.
If you need to install Apache web server on Ubuntu 20.04 from the beginning, it is recommended to use our tutorial How to Install Apache Web Server on Ubuntu 20.04
Table of Contents
- Recommended OS: Ubuntu 20.04 or higher.
- User account: A user account with sudo or root access.
- Required Software: Existing Apache Webserver
Updating Operating System
First, before anything, update your Ubuntu operating system to make sure all existing packages are up to date:
sudo apt update && sudo apt upgrade -y
Root or Sudo Access
By default, the account created with Ubuntu was giving sudo status. Still, suppose you need to provide additional accounts sudo/root access. In that case, you must either have access to the root password to use the su command or visit our tutorial on How to Add a User to Sudoers on Ubuntu.
Install Latest Apache
Before you begin, you should establish the version of Apache 2 webserver you have currently running:
Server version: Apache/2.4.41 (Ubuntu)
Adding Apache PPA
The first step in upgrading your Ubuntu 20.04 Apache webserver to the latest version is adding the PPA by Ondřej Surý’s. For those unfamiliar, Ondřej is the maintainer for PHP on Debian and maintains the latest Apache PPA for Ubuntu along with Nginx and PHP.
To add the PPA, use the following command in your terminal:
sudo add-apt-repository ppa:ondrej/apache2 -y && sudo apt update
This will automatically add the PPA and refresh to update your repository list.
Upgrade Apache from PPA
Now, you can run the apt package manager install command, which will upgrade Apache 2 web server as follows:
sudo apt install apache2
Alternatively, you can use the update and upgrade as follows:
sudo apt update
If an Apache 2 upgrade is available the run the following:
sudo apt upgrade apache2 -y
Verify version and Apache status
Once the upgrade is complete, check the version of Apache you are using now with the following command:
Server version: Apache/2.4.51 (Ubuntu)
As you can see, the version has changed from the Ubuntu default repository version Apache 2 build is 2.4.41 to the latest Apache build provided by the PPA by Ondřej Surý build 2.4.51.
Lastly, verify the status by using the following systemctl command:
sudo systemctl status apache2
Congratulations, you have upgraded Apache to the latest version on offer.
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 Keep Apache Updated
To update Apache in the future, all you need to do is run the apt update command as the new repository is added to the apt source list:
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.
Comments and Conclusion
In this small tutorial, you have learned how to upgrade Ubuntu 20.04 to the latest version of Apache 2 webserver. Overall, using the latest versions in the Ubuntu repository can benefit from having the latest features and bug improvements. The only downside is always if the maintainer upgrades the PPA quickly if a security patch comes out for a known exploit. HOWEVER, the PPA by Ondřej is maintained quite well and is often updated very quickly, so you should have confidence using this PPA.