How to install php 7.4 on Debian
To install PHP 7.4 on Debian 12, you need to add a third-party repository because PHP 7.4 is not available in the default Debian 12 repositories (which typically include newer versions of PHP). Here’s a step-by-step guide:
Step 1: Update Your System
Before installing any new software, update your system to ensure all existing packages are up to date.
sudo apt update && sudo apt upgrade -y
Step 2: Add a Third-Party Repository for PHP 7.4
Debian 12 does not include PHP 7.4 in its default repositories, so you need to add a third-party repository like deb.sury.org (maintained by Ondřej Surý).
Install the required dependencies
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common curl
Add the repository
curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x
Update the package list
sudo apt update
Step 3: Install PHP 7.4
Now that the repository is added, you can install PHP 7.4.
Install PHP 7.4
sudo apt install -y php7.4
Install additional PHP 7.4 modules (optional but recommended)
sudo apt install -y php7.4-cli php7.4-fpm php7.4-common php7.4-mysql php7.4-curl php7.4-gd php7.4-mbstring php7.4-xml php7.4-zip
Step 4: Verify the Installation
Check the installed PHP version to confirm the installation was successful.
php -v
You should see output similar to:
PHP 7.4.x (cli) (built: ...)
Step 5: Configure PHP (Optional)
If you installed php7.4-fpm, you may want to configure it for use with a web server like Nginx or Apache.
Edit the PHP-FPM configuration file
sudo nano /etc/php/7.4/fpm/php.ini
Restart PHP-FPM after making changes
sudo systemctl restart php7.4-fpm
Step 6: Set PHP 7.4 as the Default PHP Version (Optional)
If you have multiple PHP versions installed and want to set PHP 7.4 as the default, use the update-alternatives command.
Set PHP 7.4 as the default CLI version
sudo update-alternatives --set php /usr/bin/php7.4
Verify the default PHP version
php -v
Step 7: Remove the Repository (Optional)
If you don’t plan to use the third-party repository for other purposes, you can remove it to avoid potential conflicts.
Remove the repository
sudo rm /etc/apt/sources.list.d/php.list
Update the package list
sudo apt update
Notes:
- Security: PHP 7.4 reached its end of life (EOL) on November 28, 2022, and no longer receives security updates. It is recommended to use a supported version of PHP (e.g., PHP 8.x) if possible.
- Compatibility: Ensure that your applications are compatible with PHP 7.4 before using it in production.
By following these steps, you should have PHP 7.4 successfully installed on Debian 12.

