Update system repositories
To update the system repositories, use the command shown below.
sudo apt update
Install all necessary prerequisites
Following the update of the system packages, the following requirements for PHP 8 must be installed
sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y
Set up PHP repository
Then, use the following command to add the PHP 8 repository to your system repositories:
sudo add-apt-repository ppa:ondrej/php
To allow the prompt to continue, press "Enter":
Install PHP 8 on Ubuntu 22.04
We have now installed the necessary dependencies and added the PHP repository. We'll now proceed to install PHP 8 on our Ubuntu 22.04 machine using the instructions below.
To enable the system to finish installing PHP 8, type "y":
sudo apt install php8.1
Verify PHP version
You can check the version of PHP that is installed by using the "php" command with the "-v" option
php -v
Conclusion
First, update the system repositories and install the essential components before installing PHP 8 on Ubuntu 22.04. Then, add the PHP repository by running "$ sudo add-apt-repository ppa:ondrej/php" and install PHP 8 by running "$ sudo apt install php8.1." You may enhance your web development experience by installing its available extensions.