Recommended Steps Before Installation
Before you begin, run an update on your system to ensure all packages are up-to-date to avoid any conflicts during the installation.
sudo apt update
Proceed to upgrade any outdated packages using the following command.
sudo apt upgrade
Adding Apache Repository by Ondřej Surý Repository
The first step is to import the Apache webserver to the latest version is add the repository by Ondřej Surý.
Before you begin, run the following command to ensure these packages are present; most users should be already installed on your system.
sudo apt install dirmngr ca-certificates software-properties-common gnupg gnupg2 apt-transport-https -y
Importing GPG keys from Ubuntu’s KeyServer, a common issue is that your command line terminal may not create the necessary directories. Run this to create these directories.
sudo gpg --list-keys
What you should see:
gpg: directory '/root/.gnupg' created
gpg: keybox '/root/.gnupg/pubring.kbx' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
The next task is to import the GPG key needed.
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/ondrej.gpg --keyserver keyserver.ubuntu.com --recv-keys 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C
Example output:
gpg: keybox '/usr/share/keyrings/ondrej.gpg' created
gpg: key 4F4EA0AAE5267A6C: public key "Launchpad PPA for Ondřej Surý" imported
gpg: Total number processed: 1
gpg: imported: 1
Ensure success with your installation by choosing the correct command for the version of Ubuntu you’re running! It’s easy – import your GPG key and select a LaunchPAD PPA that matches.
Below only run the one for your version of Ubuntu 20 or 22 :
lsb_release -a
What you should see
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal
Import Apache PPA for Ubuntu 22.04 LTS Jammy Jellyfish LTS
echo 'deb [signed-by=/usr/share/keyrings/ondrej.gpg] https://ppa.launchpadcontent.net/ondrej/apache2/ubuntu jammy main' | sudo tee -a /etc/apt/sources.list.d/apache2.list
Import Apache PPA for Ubuntu 20.04 LTS Focal Fossa LTS
echo 'deb [signed-by=/usr/share/keyrings/ondrej.gpg] https://ppa.launchpadcontent.net/ondrej/apache2/ubuntu focal main' | sudo tee -a /etc/apt/sources.list.d/apache2.list
Install or Upgrade Apache
Update your repository to reflect the new change.
sudo apt update
With the PPA now added, you can install the latest Apache version from the PPA or upgrade your existing one. The upgrade option below will update your apache2 to the latest version.
sudo apt install apache2
or
sudo apt upgrade
sudo service apache2 restart
apache2 -v
before you would have seen
Server version: Apache/2.4.41 (Ubuntu)
Server built: 2022-06-14T13:30:55
now you will see
Server version: Apache/2.4.54 (Ubuntu)
Server built: 2022-06-08T15:59:07