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
Matching infrastructure at centron
Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →
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 -yInstall essential dependencies:
$ sudo apt install -y lsb-release apt-transport-https ca-certificatesImport the SURY GPG key for repository validation:
$ sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpgAdd 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.listRefresh the package index again:
$ sudo apt update -yCheck available PHP versions in the repository:
$ sudo apt policy phpOutput 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.4Verify installation:
$ php8.4 -vList installed versions:
$ ls /etc/phpIf 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 84Then confirm:
$ php -vInstall 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 -mInstall 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-fpmEdit the pool configuration file:
$ sudo nano /etc/php/8.4/fpm/pool.d/www.confSet the socket PHP-FPM will use:
listen = /run/php/php8.4-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660Enable PHP-FPM on boot:
$ sudo systemctl enable php8.4-fpmRestart PHP-FPM:
$ sudo systemctl restart php8.4-fpmCheck service status:
$ sudo systemctl status php8.4-fpmTest and Use PHP with Apache
Now connect PHP-FPM with Apache using proxy_fcgi.
Install Apache:
$ sudo apt install -y apache2Enable required modules:
$ sudo a2enmod proxy_fcgi setenvif
$ sudo a2enconf php8.4-fpmRestart Apache:
$ sudo systemctl restart apache2Create a sample PHP file:
$ sudo nano /var/www/html/sample.phpInsert:
<!--?php phpinfo(); ?-->Allow firewall access:
$ sudo ufw allow 80/tcp
$ sudo ufw reloadVisit 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.
Testen Sie Ihr Setup auf ccloud³
Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.