Quick Answer
Install older/newer PHP versions on Debian/Ubuntu.
Understanding the Issue
Default repositories may not have all PHP versions. Use third-party repositories like ondrej/php.
The Problem
This code demonstrates the issue:
Bash
Error
# Need PHP 7.4 on Debian 11
The Solution
Here's the corrected code:
Bash
Fixed
# Add ondrej/php PPA
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
# Install specific version
sudo apt install php7.4 php7.4-fpm php7.4-mysql
# Switch between versions
sudo update-alternatives --config php
# Verify
php -v
# Install additional extensions
sudo apt install php7.4-{gd,mbstring,xml,zip,curl}
Key Takeaways
Use third-party repositories for non-standard PHP versions.