Install and Configure PHP 8.4 with PHP-FPM on Debian 12
PHP (Hypertext Preprocessor) is an open-source server-side scripting language widely used to create interactive websites and web applications. The PHP 8.x series delivers major performance boosts, introducing features such as Just-In-Time (JIT) compilation, named arguments, and union types that modernize the development workflow and improve efficiency.
This guide explains how to install PHP 8.4 on Debian 12, configure PHP-FPM for better request handling, and integrate it with the Apache web server.
Prerequisites
- A Debian 12 server
- Access as a non-root user with sudo privileges
Add the PHP PPA Repository
Debian 12’s default APT repositories may not always provide the newest PHP versions. The SURY repository, maintained by Ondřej Surý (Debian’s PHP package maintainer), offers updated and trusted PHP builds.
First, update your system and upgrade packages:
$ sudo apt update && sudo apt upgrade -y
Install essential dependencies:
$ sudo apt install -y lsb-release apt-transport-https ca-certificates
Import the SURY GPG key for repository validation:
$ sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
Add the SURY repository to your APT sources:
$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
Refresh the package index again:
$ sudo apt update -y
Check available PHP versions in the repository:
$ sudo apt policy php
Output shows PHP 8.4 available from the SURY repository.
Install PHP 8.4
Install PHP 8.4 with common extensions required for database connectivity, string manipulation, and API communication.
$ sudo apt install -y php8.4
Verify installation:
$ php8.4 -v
List installed versions:
$ ls /etc/php
If PHP 8.4 is the only version installed, set it as the default:
$ sudo update-alternatives --install /usr/bin/php php /usr/bin/php8.4 84
Then confirm:
$ php -v
Install common PHP extensions:
$ sudo apt install -y php8.4-mysql php8.4-curl php8.4-xml php8.4-mbstring
- php8.4-mysql: Database connectivity for MySQL/MariaDB
- php8.4-curl: Remote data fetching
- php8.4-xml: XML parsing support
- php8.4-mbstring: Multibyte string handling for UTF-8
Verify active PHP modules:
$ php8.4 -m
Install PHP-FPM 8.4
PHP-FPM (FastCGI Process Manager) separates PHP execution from the web server for better scalability and performance.
Install PHP-FPM:
$ sudo apt install -y php8.4-fpm
Edit the pool configuration file:
$ sudo nano /etc/php/8.4/fpm/pool.d/www.conf
Set the socket PHP-FPM will use:
listen = /run/php/php8.4-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
Enable PHP-FPM on boot:
$ sudo systemctl enable php8.4-fpm
Restart PHP-FPM:
$ sudo systemctl restart php8.4-fpm
Check service status:
$ sudo systemctl status php8.4-fpm
Test and Use PHP with Apache
Now connect PHP-FPM with Apache using proxy_fcgi
.
Install Apache:
$ sudo apt install -y apache2
Enable required modules:
$ sudo a2enmod proxy_fcgi setenvif
$ sudo a2enconf php8.4-fpm
Restart Apache:
$ sudo systemctl restart apache2
Create a sample PHP file:
$ sudo nano /var/www/html/sample.php
Insert:
Allow firewall access:
$ sudo ufw allow 80/tcp
$ sudo ufw reload
Visit http://SERVER-IP/sample.php
in a browser to confirm PHP is working.
Conclusion
You have successfully installed PHP 8.4 and PHP-FPM on Debian 12, configured Apache integration, and tested the setup with a sample script. This environment is now ready for deploying modern PHP-based applications. For additional configuration and performance tuning, refer to the official PHP documentation.