Here we have summed up steps using which you can with great ease install the latest version of PHP in Ubuntu 22.04.
Install the latest PHP on Ubuntu 22.04
The guide below teaches you how to install the latest PHP on Ubuntu 22.04.
Step 1: Update the system
To avoid any conflicts during the installation procedure make sure your system is updated. This can be done using this command.
The system has been updated.
Step 2: Install Dependencies
To install PHP with success you have to install dependencies and to do so run the below-given command. These dependencies might already exist on your system, however, running this command confirms their presence.
This makes sure the dependencies are installed.
Step 3: Import PPA Repository of PHP
The next step is to import PPA repository from Ondřej Surý who is a renowned PHP and Debian developer and maintains its packages as well as Ubuntu’s packages.
Now update the system once again using the command provided in step 1.
Step 4: Install Apache module/PHP-FPM
There can be two ways to install PHP:
1. Using Apache Module
If you are an Apache HTTP server user and want to install php’s latest version with Apache, then execute the command given below:
After this, you would require to start your Apache server again so that the new PHP module is loaded.
To evaluate its status.
2. Using Nginx(PHP-FPM)
Run this to install PHP.
After this make sure your PHP-FPM is working properly. Use this command to confirm this.
Step 5: Verify installation
Lastly, verify the successful installation of PHP on your system using this command. For this blog, we have installed PHP using the Apache module.
We have installed PHP with great ease.
Step 6: Install Extensions
There are numerous extensions of PHP available so if you desire to install any one of these then you can use the following command.
However, if you want the list of all the extensions then use the following command.
Chose the extension from the list and install it using the above given command.
In order to install latest PHP on Ubuntu 22.04 you have to import PPA, then install Apache module or PHP-FPM using $ sudo apt install php8.1 libapache2-mod-php8.1, or $ sudo apt install php8.1-fpm libapache2-mod-fcgid commands respectively. Later the successful installation of PHP can be verified using the command $ php –version. Moreover, for the purpose of adding PHP extensions use this command $ php -m.