How to Install PHP on Debian 13, 12 and 11

Install Debian's default PHP on Debian 13, 12, and 11 with APT. Covers Apache, Nginx, PHP-FPM, extensions, version checks, and removal.

Last updatedAuthorJoshua JamesRead time9 minGuide typeDebian

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 sudo for 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.

Choose the Default or Version-Specific PHP Path

Use Debian’s default PHP packages when you want the branch maintained for your release. Use a version-specific PHP guide only when an application requires a branch that is not your release default.

Reader NeedBest Destination
Install Debian’s default PHP branch: PHP 8.4 on Debian 13, PHP 8.2 on Debian 12, or PHP 7.4 on Debian 11Debian default APT packages
Install PHP 8.5 on DebianInstall PHP 8.5 on Debian
Install PHP 8.4 as a fixed branch on Debian 12 or Debian 11Install PHP 8.4 on Debian
Install PHP 8.3 on DebianInstall PHP 8.3 on Debian
Install PHP 8.2 as a fixed branch on Debian 13 or Debian 11Install PHP 8.2 on Debian
Install PHP 7.4 on Debian 13 or Debian 12Debian 11’s maintained default PHP 7.4 packages; migrate or isolate legacy PHP 7.4 workloads on newer Debian releases

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.

MethodWeb ServerBest ForNotes
Apache mod_phpApache onlyDevelopment systems and smaller Apache sitesShortest setup, but Apache workers load PHP directly
Apache with PHP-FPMApacheApache sites that need cleaner PHP worker separationUse versioned phpX.Y-fpm service and Apache FPM config
Nginx with PHP-FPMNginxLEMP stacks and higher-traffic PHP sitesUses the versioned socket in /run/php/
  • Choose Apache mod_php when 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

The first line should report PHP 8.4 on Debian 13, PHP 8.2 on Debian 12, or PHP 7.4 on Debian 11.

Confirm that Apache actually loaded the PHP module before you move on. The module name is generic on Debian 12 and Debian 13 but versioned on Debian 11, so use a version-tolerant match.

sudo apache2ctl -M | grep -E 'php[0-9]*_module'

The command should print php_module (shared) on Debian 12 or Debian 13, or php7_module (shared) on Debian 11. Either match confirms Apache loaded the PHP module.

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 php-cli php-fpm

Do not install libapache2-mod-fcgid for this path. Debian’s PHP-FPM package already ships the Apache proxy_fcgi configuration file, and the next commands enable the Apache modules that configuration needs.

If mod_php is already enabled, disable the versioned module name before switching Apache to PHP-FPM: sudo a2dismod php8.4 on Debian 13, sudo a2dismod php8.2 on Debian 12, or sudo a2dismod php7.4 on Debian 11. The generic sudo a2dismod php form fails on Debian with Module 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 active state with the command that matches your release.

For Debian 13 (PHP 8.4):

systemctl is-active php8.4-fpm

For Debian 12 (PHP 8.2):

systemctl is-active php8.2-fpm

For Debian 11 (PHP 7.4):

systemctl is-active php7.4-fpm

A healthy PHP-FPM service prints active.

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.

For Debian 13 (PHP 8.4):

sudo systemctl enable php8.4-fpm --now

For Debian 12 (PHP 8.2):

sudo systemctl enable php8.2-fpm --now

For Debian 11 (PHP 7.4):

sudo systemctl enable php7.4-fpm --now

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
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload Nginx after the syntax test succeeds.

sudo systemctl reload nginx

If you want to confirm the PHP-FPM socket exists before reloading Nginx, check the versioned path directly.

For Debian 13 (PHP 8.4):

test -S /run/php/php8.4-fpm.sock && printf 'PHP-FPM socket exists\n'

For Debian 12 (PHP 8.2):

test -S /run/php/php8.2-fpm.sock && printf 'PHP-FPM socket exists\n'

For Debian 11 (PHP 7.4):

test -S /run/php/php7.4-fpm.sock && printf 'PHP-FPM socket exists\n'

A successful socket check prints PHP-FPM socket exists.

For a complete server block workflow with request tests, use the dedicated guide to configure Nginx with PHP-FPM.

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

The first line should match the default branch for the release: PHP 8.4 on Debian 13, PHP 8.2 on Debian 12, or PHP 7.4 on Debian 11.

The package check should show an installed version and the 100 /var/lib/dpkg/status line for each metapackage. The same installed-state pattern appears for php-fpm and php-cli.

apt-cache policy php php-fpm php-cli

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 May 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 ReleaseDefault php MetapackageRuntime PackageWhat That Means
Debian 13 (Trixie)2:8.4+96php8.4 at 8.4.21-1~deb13u1Best fit for new projects that support PHP 8.4 out of the box
Debian 12 (Bookworm)2:8.2+93php8.2 at 8.2.31-1~deb12u1Bookworm’s default branch for applications targeting PHP 8.2
Debian 11 (Bullseye)2:7.4+76php7.4 at 7.4.33-1+deb11u11Legacy branch for older applications that still require PHP 7.4

PHP 7.4 is upstream end-of-life, but Debian 11 still receives LTS package maintenance until August 31, 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.

Keep branch-specific installs separate from this default-package flow because they use a third-party PHP repository and branch-specific packages. Mixing both paths without a deliberate plan can change the active CLI or PHP-FPM branch.

PHP 7.4 is different from the newer fixed-branch options. It is upstream end-of-life and remains relevant only because Debian 11 maintains PHP 7.4 as its default package branch; Debian 12 and Debian 13 users should plan a migration or isolate legacy applications instead of treating PHP 7.4 as a normal new target.

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.

For Debian 13 (PHP 8.4):

sudo systemctl restart php8.4-fpm

For Debian 12 (PHP 8.2):

sudo systemctl restart php8.2-fpm

For Debian 11 (PHP 7.4):

sudo systemctl restart php7.4-fpm

Restart the web server that serves the PHP site after the PHP-FPM restart.

sudo systemctl restart nginx

For Apache-served sites, restart Apache instead.

sudo systemctl restart apache2

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.

For Debian 13 (PHP 8.4):

apt-cache search "^php8.4-"

For Debian 12 (PHP 8.2):

apt-cache search "^php8.2-"

For Debian 11 (PHP 7.4):

apt-cache search "^php7.4-"

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. The examples use Debian 12; replace 8.2 with 8.4 on Debian 13 or 7.4 on Debian 11.

systemctl is-active php8.2-fpm
test -S /run/php/php8.2-fpm.sock && printf 'PHP-FPM socket exists\n'

If the service is inactive, start it and check the socket again.

sudo systemctl enable php8.2-fpm --now
systemctl is-active php8.2-fpm
test -S /run/php/php8.2-fpm.sock && printf 'PHP-FPM socket exists\n'
active
PHP-FPM socket exists

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.

For Debian 13 (PHP 8.4):

sudo a2enmod php8.4
sudo systemctl restart apache2

For Debian 12 (PHP 8.2):

sudo a2enmod php8.2
sudo systemctl restart apache2

For Debian 11 (PHP 7.4):

sudo a2enmod php7.4
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 -E 'php[0-9]*_module'

The command should print php_module (shared) on Debian 12 or Debian 13, or php7_module (shared) on Debian 11.

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. The examples use Debian 12 because it follows the common versioned package pattern.

dpkg-query -W -f='${binary:Package}\n' php8.2-curl
php -m | grep -i '^curl$'
php8.2-curl
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. Review the package list before confirming, especially on servers that already have another PHP branch or application-managed PHP packages.

For Debian 13 (PHP 8.4):

sudo apt purge 'php8.4*' php php-cli php-fpm libapache2-mod-php

For Debian 12 (PHP 8.2):

sudo apt purge 'php8.2*' php php-cli php-fpm libapache2-mod-php

For Debian 11 (PHP 7.4):

sudo apt purge 'php7.4*' php php-cli php-fpm libapache2-mod-php php-imagick php-memcached php-redis php-apcu php-xdebug

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). If another PHP branch remains installed, the generic metapackages may still resolve to that branch instead.

sudo apt update
apt-cache policy php php-fpm php-cli

If the CLI package was removed and no other PHP branch remains installed, Debian no longer resolves the php command.

php --version
bash: php: command not found

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.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Verify before posting: