sudo apt install gnupg apt-transport-https ca-certificates
wget -qO - https://packages.sury.org/php/apt.gpg | sudo gpg --dearmor -o /usr/share/keyrings/sury-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/sury-archive-keyring.gpg] https://packages.sury.org/php/ bookworm main" | sudo tee /etc/apt/sources.list.d/sury-php.list
sudo apt install php8.4 php8.4-cli
To install a different version, just replace 8.4 with your version like 8.0 or 7.4 etc. The available versions are PHP 8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, and PHP 5.6.
You may also need to install other php modules based on your project requirements. Make sure to change PHP version as per your version.
sudo apt install php8.4-mysql php8.4-curl php8.4-xml php8.4-mbstring
If your application required a web server to serve website content, install Apache with PHP module.
sudo apt install apache2 libapache2-mod-php8.4