Share your love
Install PHP 8.2 on Ubuntu 22.04: Easy Setup

In this tutorial, we want to teach you How To Install PHP 8.2 on Ubuntu 22.04. PHP is a server-side scripting language that is used to develop Static websites or Dynamic websites or Web applications. It stands for Hypertext Pre-processor, which earlier stood for Personal Home Pages.
PHP scripts can only be interpreted on a server that has PHP installed. The client computers accessing the PHP scripts require a web browser only. A PHP file contains PHP tags and ends with the extension “.php”.
You can now follow the guide steps below on the Orcacore website to set up PHP 8.2 Ubuntu 22.04.
Table of Contents
Steps To Install PHP 8.2 on Ubuntu 22.04
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Ubuntu 22.04.
In this guide, you will learn to install PHP 8.2 with Apache and Nginx Modules.
Import Ondřej Surý PHP PPA on Ubuntu 22.04
To successfully install PHP 8.2, you will need to import the renowned PPA from Ondřej Surý, the lead developer on PHP and Debian, and maintain Ubuntu and Debian packages.
To install Ondřej Surý PPA and the required packages on Ubuntu 22.04, run the following command:
sudo apt install software-properties-common -y && sudo add-apt-repository ppa:ondrej/php -y
Then, update and upgrade your local package index with the command below:
sudo apt update && sudo apt upgrade
Set up PHP 8.2 on Ubuntu 22.04
At this point, you can install PHP 8.2 with an Apache option and an Nginx option.
Installing PHP 8.2 for Apache on Ubuntu 22.04
If you run an Apache HTTP server, you can run PHP as an Apache module or PHP-FPM.
To install PHP 8.2 as an Apache module, enter the following command:
sudo apt install php8.2 libapache2-mod-php8.2 -y
When your installation is completed, restart Apache for the new PHP module to be loaded:
sudo systemctl restart apache2
Also, you can install Apache with PHP-FPM. To do this, run the following command:
sudo apt install php8.2-fpm libapache2-mod-fcgid
Enable PHP-FPM for Apache on Ubuntu 22.04
Note: PHP-FPM is not enabled for Apache. You must enable it by the following command:
sudo a2enmod proxy_fcgi setenvif && sudo a2enconf php8.2-fpm
Restart Apache to apply the changes:
sudo systemctl restart apache2
Verify that your PHP-FPM service is active and running on your server:
sudo systemctl status php8.2-fpm

You can verify your PHP installation on Ubuntu 22.04, with the command below:
php --version

Installing PHP 8.2 for Nginx on Ubuntu 22.04
Nginx does not contain native PHP processing like some other web servers like Apache. You will need to install PHP-FPM “fastCGI process manager” to handle the PHP files.
Install PHP 8.2 and PHP 8.2-FPM with the following command:
sudo apt install php8.2 php8.2-fpm php8.2-cli -y
Verify your PHP-FPM service is active and running on your server with the command below:
sudo systemctl status php8.2-fpm

Also, you need to edit your Nginx server block and add the example below for Nginx to process the PHP files on Ubuntu 22.04.
server {
# … some other code
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
Test Nginx to make sure you have no errors with the adjustments made with the code above; enter the following command:
sudo nginx -t

Then, restart Nginx to apply the changes:
sudo systemctl restart nginx
Also, you can verify your PHP 8.2 installation on Ubuntu 22:
php --version

Conclusion
At this point, you learn to Install PHP 8.2 on Ubuntu 22.04. PHP 8.2 PHP is a server-side scripting language that helps you to develop Static websites or Dynamic websites or Web applications.
Hope you enjoy it. Please subscribe to us on Facebook, YouTube, and Twitter.
You may also like these articles:
How To Set up PiVPN on Ubuntu 22.04