Watch the video:
0:14 - Installing PHP8.1
1:00 - Installing PHP Extensions
1:52 - Linking PHP with Nginx
3:09 - Verify sites have PHP handling set
This was recorded a while ago and shows installing and enabling PHP 8.1 for an Nginx server. This video should work for newer versions as well. By the end, you should know how to enable PHP to start using PHP files and more on your Nginx web server on Ubuntu or Debian.
Update:
sudo apt update && sudo apt upgrade
Install PHP:
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.1-fpm
PHP Extensions:
sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-redis php8.1-intl
Linking PHP with Nginx:
sudo nano /etc/php/8.1/fpm/php.ini
sudo service php8.1-fpm restart