Most Debian web stacks stop at static HTML until PHP is in place. You can install PHP on Debian from the default APT sources and pair it with Apache or Nginx. The release decides the branch you get: Debian 13 (Trixie) installs PHP 8.4, Debian 12 (Bookworm) installs PHP 8.2, and Debian 11 (Bullseye) installs PHP 7.4.
The generic php, php-fpm, and php-cli packages follow that default branch automatically. That same default-package flow covers Apache mod_php, Apache with PHP-FPM, Nginx with PHP-FPM, the common extension set, troubleshooting, and clean removal. Move to a version-specific guide only when the application needs a different branch.
Install PHP on Debian
Debian’s php, php-fpm, and php-cli metapackages install the default branch for your release. Pick the web server integration that matches your stack first, and use a version-specific PHP guide only when the application needs a newer or older PHP branch.
Update Debian Before Installing PHP on Debian
Refresh APT metadata first so Debian resolves the current PHP packages from its default repositories and security updates.
sudo apt update
sudo apt upgrade
These commands use
sudofor tasks that need root privileges. If your account is not in the sudoers file yet, follow the guide to add a user to sudoers on Debian.
Compare PHP Integration Methods on Debian
PHP can run inside Apache through mod_php or as a separate PHP-FPM service behind Apache or Nginx. The package names stay simple, but the handler choice changes performance, process isolation, and which Apache or Nginx configuration you need.
| Method | Web Server | Best For | Notes |
|---|---|---|---|
Apache mod_php | Apache only | Development systems and smaller Apache sites | Shortest setup, but Apache workers load PHP directly |
| Apache with PHP-FPM | Apache | Apache sites that need cleaner PHP worker separation | Use versioned phpX.Y-fpm service and Apache FPM config |
| Nginx with PHP-FPM | Nginx | LEMP stacks and higher-traffic PHP sites | Uses the versioned socket in /run/php/ |
- Choose Apache
mod_phpwhen you want the shortest working Apache setup. - Choose Apache with PHP-FPM when Apache is already in place and you want PHP handled by a separate service.
- Choose Nginx with PHP-FPM when you want the usual LEMP layout and direct control over the PHP-FPM socket path.
Install PHP with Apache mod_php on Debian
Use this path when Apache is already your web server and you want the fewest moving parts. If Apache is not installed yet, start with install Apache on Debian, then add the PHP module.
sudo apt install php libapache2-mod-php
sudo systemctl restart apache2
The libapache2-mod-php metapackage installs the versioned Apache module that matches your release, such as libapache2-mod-php8.4 on Debian 13 or libapache2-mod-php8.2 on Debian 12.
Check the CLI version first so you can confirm which branch Debian installed for your release.
php --version
PHP 8.4.x (cli) (built: ...)
Copyright (c) The PHP Group
Zend Engine v4.4.x, Copyright (c) Zend Technologies
with Zend OPcache v8.4.x, Copyright (c), by Zend Technologies
Confirm that Apache actually loaded the PHP module before you move on. The grep filter keeps the module list short; if you want a broader refresher on matching output, see the grep command guide.
sudo apache2ctl -M | grep php_module
php_module (shared)
Install PHP with Apache and PHP-FPM on Debian
Apache with PHP-FPM keeps PHP in a separate FastCGI process pool, which makes memory and process management cleaner than mod_php. If Apache is not installed yet, start with install Apache on Debian so the service and vhost layout are already in place.
sudo apt install php-fpm libapache2-mod-fcgid
If
mod_phpis already enabled, disable the versioned module name before switching Apache to PHP-FPM:sudo a2dismod php8.4on Debian 13,sudo a2dismod php8.2on Debian 12, orsudo a2dismod php7.4on Debian 11. The genericsudo a2dismod phpform fails on Debian withModule php does not exist.
Enable the Apache proxy modules and the versioned PHP-FPM configuration that matches your release.
For Debian 13 (PHP 8.4):
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm
sudo systemctl enable php8.4-fpm --now
sudo systemctl restart apache2
For Debian 12 (PHP 8.2):
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.2-fpm
sudo systemctl enable php8.2-fpm --now
sudo systemctl restart apache2
For Debian 11 (PHP 7.4):
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.4-fpm
sudo systemctl enable php7.4-fpm --now
sudo systemctl restart apache2
Debian 13 uses the php8.4-fpm.service unit, Debian 12 uses php8.2-fpm.service, and Debian 11 uses php7.4-fpm.service. Check the service state with the command that matches your release.
sudo systemctl status php8.4-fpm --no-pager # Debian 13
sudo systemctl status php8.2-fpm --no-pager # Debian 12
sudo systemctl status php7.4-fpm --no-pager # Debian 11
● php8.2-fpm.service - The PHP 8.2 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.2-fpm.service; enabled; preset: enabled)
Active: active (running)
Install PHP with Nginx and PHP-FPM on Debian
Nginx always uses PHP-FPM for PHP execution. If Nginx is not installed yet, start with install Nginx on Debian, then add the PHP packages and the socket block that matches your release.
sudo apt install php php-fpm php-cli
Enable the matching PHP-FPM service for your release.
sudo systemctl enable php8.4-fpm --now # Debian 13
sudo systemctl enable php8.2-fpm --now # Debian 12
sudo systemctl enable php7.4-fpm --now # Debian 11
Debian 12 installs the php8.2-fpm package and creates the /run/php/php8.2-fpm.sock socket. Debian 13 and Debian 11 use the same pattern with php8.4-fpm and php7.4-fpm.
For Debian 13 (PHP 8.4):
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
For Debian 12 (PHP 8.2):
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
For Debian 11 (PHP 7.4):
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
Test the Nginx configuration before you reload the service so socket typos do not break the site.
sudo nginx -t
sudo systemctl reload nginx
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
If you want to confirm the PHP-FPM socket exists before reloading Nginx, check the versioned path directly.
ls -l /run/php/php8.4-fpm.sock # Debian 13
ls -l /run/php/php8.2-fpm.sock # Debian 12
ls -l /run/php/php7.4-fpm.sock # Debian 11
srw-rw---- 1 www-data www-data 0 Mar 15 14:03 /run/php/php8.2-fpm.sock
Verify PHP on Debian
Finish with a CLI version check and a package-manager check. The CLI confirms the binary is in your PATH, while apt-cache policy confirms the Debian metapackages are installed from the default APT sources.
php --version
PHP 8.4.x (cli) (built: ...)
Copyright (c) The PHP Group
Zend Engine v4.4.x, Copyright (c) Zend Technologies
with Zend OPcache v8.4.x, Copyright (c), by Zend Technologies
The package check should show an installed version and the 100 /var/lib/dpkg/status line. The same installed-state pattern appears for php-fpm and php-cli too.
apt-cache policy php php-fpm php-cli
php:
Installed: 2:x.y+xx
Candidate: 2:x.y+xx
Version table:
*** 2:x.y+xx 500
500 http://deb.debian.org/debian [release]/main amd64 Packages
100 /var/lib/dpkg/status
Compare PHP Versions on Debian
Application compatibility often matters more than raw feature count, so check Debian’s default mapping before you reach for a different PHP branch. As of March 2026, Debian’s default APT sources map the php metapackage to 2:8.4+96 on Debian 13, 2:8.2+93 on Debian 12, and 2:7.4+76 on Debian 11.
Compare Default PHP Versions by Debian Release
These version mappings match the current Debian 13, 12, and 11 default APT sources. The metapackage version comes from apt-cache policy php, while the runtime package version comes from the versioned PHP package for each release.
| Debian Release | Default php Metapackage | Runtime Package | What That Means |
|---|---|---|---|
| Debian 13 (Trixie) | 2:8.4+96 | php8.4 at 8.4.16-1~deb13u1 | Best fit for new projects that support PHP 8.4 out of the box |
| Debian 12 (Bookworm) | 2:8.2+93 | php8.2 at 8.2.30-1~deb12u1 | Stable default branch for current Bookworm servers |
| Debian 11 (Bullseye) | 2:7.4+76 | php7.4 at 7.4.33-1+deb11u10 | Legacy branch for older applications that still require PHP 7.4 |
PHP 7.4 is upstream end-of-life, but Debian 11 still backports security fixes through its own package maintenance window until August 2026. That keeps older applications running, but new deployments are better off on Debian 12 or Debian 13.
Use a Version-Specific PHP Guide on Debian
Debian 13 cannot install PHP 8.2 or PHP 7.4 from the default repositories, and Debian 12 cannot install PHP 8.4 or PHP 8.5 without a third-party repository. When your application needs a different branch, use the matching Debian guide instead of forcing the default package past its intended version.
- Use the guide to install PHP 8.5 on Debian when you need PHP 8.5 on Debian 13, 12, or 11.
- Use the guide to install PHP 8.4 on Debian when Debian 12 or Debian 11 needs PHP 8.4, or when you want PHP 8.4 alongside another branch.
- Use the guide to install PHP 8.3 on Debian when your application targets PHP 8.3 across all supported Debian releases.
- Use the guide to install PHP 8.2 on Debian when Debian 13 or Debian 11 must match Bookworm’s default PHP branch.
Install PHP Extensions on Debian
Most PHP applications need more than the base interpreter. Database drivers, image libraries, caching modules, and multibyte string support usually show up early in WordPress, Laravel, Symfony, and custom application stacks.
Install Common PHP Extensions on Debian
Install the common extension set that matches your Debian release. These package names cover the usual database, image, caching, compression, and localization modules used by modern PHP applications.
For Debian 13 (PHP 8.4):
sudo apt install php8.4-curl php8.4-mysql php8.4-gd php8.4-opcache php8.4-zip php8.4-intl php8.4-common php8.4-bcmath php8.4-imagick php8.4-xmlrpc php8.4-readline php8.4-memcached php8.4-redis php8.4-mbstring php8.4-apcu php8.4-xml
For Debian 12 (PHP 8.2):
sudo apt install php8.2-curl php8.2-mysql php8.2-gd php8.2-opcache php8.2-zip php8.2-intl php8.2-common php8.2-bcmath php8.2-imagick php8.2-xmlrpc php8.2-readline php8.2-memcached php8.2-redis php8.2-mbstring php8.2-apcu php8.2-xml
For Debian 11 (PHP 7.4):
sudo apt install php7.4-curl php7.4-mysql php7.4-gd php7.4-opcache php7.4-zip php7.4-intl php7.4-common php7.4-bcmath php7.4-xmlrpc php7.4-readline php7.4-mbstring php7.4-xml php7.4-json php-imagick php-memcached php-redis php-apcu
Debian 11 keeps several PECL-based extensions under unversioned package names such as php-imagick, php-memcached, php-redis, and php-apcu. Debian 12 and Debian 13 use versioned package names for those same modules.
There is no separate php8.2-openssl or php8.4-openssl package in Debian. OpenSSL support ships with Debian’s main PHP packages and appears in php -m after the base install.
Restart the matching PHP-FPM service after adding extensions. Apache mod_php users only need to restart Apache.
sudo systemctl restart php8.4-fpm # Debian 13
sudo systemctl restart php8.2-fpm # Debian 12
sudo systemctl restart php7.4-fpm # Debian 11
sudo systemctl restart nginx # Or apache2 if Apache serves the site
Search for More PHP Extensions on Debian
Use apt-cache search with the branch prefix when you need a module outside the common set. This is cleaner than apt search here because it skips APT’s scripting warning and keeps results aligned to one PHP branch.
apt-cache search "^php8.4-" # Debian 13
apt-cache search "^php8.2-" # Debian 12
apt-cache search "^php7.4-" # Debian 11
Debian 11 still keeps some PECL-style modules under unversioned package names such as php-imagick and php-redis. If Bullseye does not show the module you expect in the php7.4- search results, run apt-cache search "^php-" too.
List Loaded PHP Modules on Debian
After the base install and common extension setup, the module list should include the core runtime plus the extensions you added.
php -m
[PHP Modules] Core curl gd intl mbstring mysqli openssl PDO pdo_mysql xml Zend OPcache zip [Zend Modules] Zend OPcache
Install PHP Development Packages on Debian
Add Xdebug and the PHP development headers when you need debugging, profiling, or local extension builds.
For Debian 13 (PHP 8.4):
sudo apt install php8.4-xdebug php8.4-dev
For Debian 12 (PHP 8.2):
sudo apt install php8.2-xdebug php8.2-dev
For Debian 11 (PHP 7.4):
sudo apt install php-xdebug php7.4-dev
Debian 11 keeps Xdebug under the unversioned php-xdebug package, while Debian 12 and Debian 13 use versioned Xdebug package names.
If your project uses image processing or object caching, the dedicated guides to install PHP ImageMagick on Debian, install Redis on Debian, and install Memcached on Debian help once the PHP extensions are already in place.
Troubleshoot PHP on Debian
The most common PHP problems on Debian come from handler mismatches, missing sockets, or extension packages that were installed but never loaded into the active PHP service.
Fix PHP-FPM Socket Not Found on Debian
Nginx usually reports this as a 502 Bad Gateway error when the configured socket path does not exist or the matching PHP-FPM service is down.
sudo tail -n 20 /var/log/nginx/error.log
connect() to unix:/run/php/php8.2-fpm.sock failed (2: No such file or directory)
Check the matching service and socket path next. Debian 12 is shown here; replace 8.2 with 8.4 on Debian 13 or 7.4 on Debian 11.
sudo systemctl status php8.2-fpm --no-pager
ls -l /run/php/php8.2-fpm.sock
If the service is inactive, start it and check the socket again.
sudo systemctl enable php8.2-fpm --now
ls -l /run/php/php8.2-fpm.sock
● php8.2-fpm.service - The PHP 8.2 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.2-fpm.service; enabled; preset: enabled)
Active: active (running)
srw-rw---- 1 www-data www-data 0 Mar 15 14:03 /run/php/php8.2-fpm.sock
Fix the “Module php does not exist” Error on Debian
Debian keeps Apache PHP module names versioned, so sudo a2enmod php and sudo a2dismod php fail even though the right module is installed. Use the branch-specific module name that matches your release instead.
sudo a2enmod php8.4 # Debian 13
sudo a2enmod php8.2 # Debian 12
sudo a2enmod php7.4 # Debian 11
sudo systemctl restart apache2
Verify the module list with sudo apache2ctl. Debian keeps apache2ctl in /usr/sbin, so an unprivileged shell often reports command not found unless you run it with sudo.
sudo apache2ctl -M | grep php_module
php_module (shared)
Fix a PHP Extension That Will Not Load on Debian
First confirm the package is installed, then confirm the module is loaded into the active PHP process. Debian 12 is shown here because it uses the common versioned package pattern.
dpkg -l | grep php8.2-curl
php -m | grep -i curl
ii php8.2-curl 8.2.x amd64 CURL module for PHP curl
Use php8.4-curl on Debian 13. Debian 11 still mixes versioned core extensions such as php7.4-curl with unversioned packages such as php-imagick and php-redis.
If the package is installed but the module is missing, restart the matching PHP-FPM service or Apache and check again. OpenSSL is built in, so you do not need a separate extension package for it.
sudo systemctl restart php8.2-fpm
php -m | grep -i curl
curl
Remove PHP from Debian
Remove the branch that matches your release first, then let APT clean up the now-unused supporting packages.
sudo apt remove --purge "php8.4*" # Debian 13
sudo apt remove --purge "php8.2*" # Debian 12
sudo apt remove --purge "php7.4*" # Debian 11
Finish with autoremove --purge so Debian removes leftover helper packages such as php-common and extension libraries that no longer have a PHP runtime to attach to.
sudo apt autoremove --purge
Refresh APT metadata again, then verify the PHP metapackages show Installed: (none).
sudo apt update
apt-cache policy php php-fpm php-cli
php:
Installed: (none)
Candidate: 2:x.y+xx
Version table:
2:x.y+xx 500
500 http://deb.debian.org/debian [release]/main amd64 Packages
If the CLI package was removed too, Debian no longer resolves the php command.
php --version
bash: php: command not found
PHP on Debian FAQ
Debian 12 installs PHP 8.2 from the default APT sources. Debian 13 installs PHP 8.4 and Debian 11 installs PHP 7.4, so use a version-specific guide when your application needs a different branch.
No. Debian 13’s default APT sources provide PHP 8.4, not PHP 8.2. If your application still needs PHP 8.2, use the separate Debian guide for that branch instead of the default package.
The versioned package is php8.2-fpm on Debian 12. Debian 13 uses php8.4-fpm, Debian 11 uses php7.4-fpm, and the generic php-fpm metapackage simply installs the default branch for your release.
No. OpenSSL support is built into Debian’s main PHP packages, so you will not find packages such as php8.2-openssl or php8.4-openssl in APT. Use php -m | grep -i openssl if you need to confirm that the module is loaded.
Conclusion
PHP is installed on Debian with the default runtime for your release, and Apache or Nginx can now hand dynamic requests to the right PHP handler. The next step is usually to install Composer on Debian for dependency management, then install MariaDB on Debian once the application stack is ready for database work.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>