How to Upgrade Apache on Ubuntu 22.04 or 20.04

Apache web server is a pivotal component for hosting applications and websites, and ensuring it’s updated is crucial for performance and security. This introduction will guide you on how to upgrade Apache on Ubuntu 22.04 Jammy Jellyfish or its older stable release of Ubuntu 20.04 Focal Fossa, providing you with the latest features and improvements available.

Key Advantages of Upgrading Apache:

  • Enhanced Performance: Running the latest version of Apache guarantees optimal performance, as each update often comes with improvements and optimizations.
  • Security Updates: Regularly upgrading Apache ensures you receive all the critical security patches, safeguarding your server against potential vulnerabilities.
  • Access to New Features: Each Apache release introduces new features and functionalities. Upgrading allows leveraging these additions for a more efficient and streamlined server management experience.
  • Bug Fixes: Updates invariably address and rectify bugs and issues identified in previous versions, leading to a more stable and reliable server environment.
  • Ondřej Surý’s Repository: Utilizing this reputable third-party repository provides a straightforward path to acquiring the latest Apache version without compiling from the source.

Upgrading Apache on your Ubuntu system is not just about gaining access to new features; it’s also a proactive measure to secure and enhance your server’s functionality. The subsequent guide will delineate the steps to successfully install and upgrade Apache on Ubuntu 22.04 or 20.04, employing Ondřej Surý’s trusted repository for a smooth and secure update process.

Step 1: Update Ubuntu Before Apache Upgrade

Update your system before beginning the installation process to avoid potential conflicts. This proactive step ensures that your system’s packages are up-to-date and compatible with the installation, facilitating a smoother and more successful upgrade process.

sudo apt update

You can proceed with the following command to upgrade any outdated packages on your system. This will ensure that your system has access to the latest software versions, which can result in improved performance and security:

sudo apt upgrade

Step 2: Import Apache LaunchPAD PPA on Ubuntu

To upgrade the Apache webserver to the latest version, add Ondřej Surý’s repository as an initial step. Ensure you have installed the following packages:

sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https

Next, import the repository using the following command:

sudo add-apt-repository ppa:ondrej/apache2 -y

Step 3: Install or Upgrade Apache on Ubuntu

The next step involves updating your repository to reflect the new changes. To do this, run the following command:

sudo apt update

After adding the PPA, install the latest Apache version or upgrade your existing one. Most users should run the installation command, even with Apache already on the system, to ensure installation of the latest version and update of all necessary dependencies. To install the latest Apache version, use the following command:

sudo apt install apache2

Ensure you have the correct version and source of Apache2 installed by using the apt-cache policy command. This command verifies that the installation of Apache2 comes from the PPA. Run the following command to check:

apt-cache policy apache2
Screenshot showing the use of apt-cache policy command to verify Apache upgrade on Ubuntu 22.04 or 20.04
Using the apt-cache policy command to confirm that Apache has been successfully upgraded on Ubuntu 22.04 or 20.04.

To ensure that Apache is running correctly, you can use the systemctl command. This command allows you to check the status of Apache and verify that it is up and running as intended.

systemctl status apache2
Screenshot showing the use of apt-cache policy command to verify Apache upgrade on Ubuntu 22.04 or 20.04
Using the apt-cache policy command to confirm that Apache has been successfully upgraded on Ubuntu 22.04 or 20.04.

If Apache isn’t activated or running, use the following command to start the web server application:

sudo systemctl start apache2

To enable Apache on system boot, use the following command:

sudo systemctl enable apache2

Additional Tips with Apache on Ubuntu 22.04 or 20.04

Configure UFW Firewall for Apache


After installing or upgrading Apache with UFW (Uncomplicated Firewall) installed, you must modify the UFW rules. This modification allows outside access to the default web ports, making your web server accessible to visitors. During installation, Apache automatically registers with UFW, providing several profiles for restricting or allowing access, simplifying the configuration process.

If you do not have UFW installed, you can install it using the following command:

sudo apt install ufw

Once you install UFW, use the following command to enable it:

sudo ufw enable

To view the available Apache profiles, use the following command:

sudo ufw app list

Example output:

Available applications:
  Apache
  Apache Full
  Apache Secure

The output should display the following profiles: Apache, Apache Full, and Apache Secure. Apache runs on port 80 (HTTP), Apache Secure runs on port 443 (HTTPS), and Apache Full allows both. The most commonly used profiles are Apache Full or Apache Secure.

The guide, as an example, will enable the (Apache) profile using the following command:

sudo ufw allow 'Apache'

Example output:

Rule added
Rule added (v6)

After you run this command, the system adds rules for IPV4 and IPV6. You can disable this profile later and activate secure-only or deactivate the Apache rule and employ the Apache Full rule instead. Following these steps allows outside access to your web server, granting visitor accessibility while upholding the security and protection that UFW offers.

Update Apache on Ubuntu 22.04 or 20.04

To update Apache on Ubuntu Linux, you can use the APT package manager. To begin, run the standard APT update commands with the following command:

sudo apt update

If an update for Apache is available, you can upgrade it by running the following command:

sudo apt upgrade

Alternatively, you can upgrade Apache on its own by using the following command:

sudo apt upgrade apache2

By completing these steps, you can ensure that your Apache version is up-to-date and running smoothly.

Remove Apache Upgrade From Ubuntu 22.04 or 20.04

If you need to remove the upgraded Apache version and restore the standard Ubuntu version, you can do so by following these steps:

First, stop the Apache service by using the following command:

sudo systemctl stop apache2

Next, remove Apache by using the following command:

sudo apt remove apache2

If you had imported the PPA to upgrade Apache, you could remove it by using the following command:

sudo add-apt-repository --remove ppa:ondrej/apache2 -y

Finally, to reflect the changes made to the APT sources list entries, run the following command:

sudo apt update

At this point, you can re-install the standard Apache version.

Conclusion

In conclusion, use the APT package manager and Ondřej Surý’s repository to update Apache on Ubuntu. Upgrading to Apache’s latest version allows you to access new features and improvements, boosting your web server’s performance and stability. Moreover, adjusting the UFW rules ensures visitor accessibility to your web server while upholding essential security and protection.

Your Mastodon Instance
Share to...