PHP 7.4 reached end of life on 28 Nov 2022 and is no longer being updated. It's strongly recommended to upgrade to the latest version as soon as possible. You can read the official PHP migration guide here.
Update the package list:
sudo apt update
Install PHP 7.4 and common extensions:
sudo apt install php7.4 php7.4-cli php7.4-fpm php7.4-json php7.4-common php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath
When prompted, confirm the installation by pressing 'Y' and then 'Enter'.
Check the installed PHP version:
php -v
You should see output similar to:
PHP 7.4.x (cli) (built: ...) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.x, Copyright (c), by Zend Technologies
Verify installed PHP modules:
php -m