How to Install and Optimize Latest PHP 8.4+ on Debian 13 using Common Extensions

In this tutorial, we will show you how to install and optimize PHP 8.4 on a Debian 13 VPS, including the most commonly used extensions for modern web applications.

PHP is a widely used, open-source, server-side scripting language designed for web development. It is used in WordPress- and Laravel-based applications, as well as in other popular e-commerce platforms such as Magento, and even in custom e-commerce or CMS platforms. Debian 13 is the first stable Debian release to ship PHP 8.4 directly from its default repositories, so no third-party PPA is required to get started. PHP 8.4 itself brings meaningful improvements over earlier versions; simply installing PHP only gets you a working interpreter with conservative, one-size-fits-all defaults.

Getting real performance out of PHP 8.4 on a production Debian 13 server means installing the right extensions for your application and tuning OPcache, PHP-FPM, and a handful of php.ini directives. That is exactly what this guide covers.

Prerequisites

Step 1: Update Your Debian 13 System

Before installing anything, refresh the package index and apply any pending updates:

# apt update && sudo apt upgrade -y

It is also a good idea to have a couple of basic utilities on hand for the steps ahead:

# apt install -y curl wget gnupg2 ca-certificates lsb-release apt-transport-https

Step 2: Install PHP 8.4 and PHP-FPM

Because Debian 13 ships PHP 8.4 as its default PHP branch, installation is a single apt command; there is no need to add Ondřej Surý’s third-party repository. We recommend running PHP through PHP-FPM (FastCGI Process Manager) rather than the older mod_php approach, since FPM handles requests in separate worker pools, uses resources more efficiently, and works with either Nginx or Apache.

Install the PHP 8.4 runtime, the CLI binary, and PHP-FPM:

# apt install -y php8.4 php8.4-fpm php8.4-cli php8.4-common

Confirm the service is enabled and running:

# systemctl enable --now php8.4-fpm
# systemctl status php8.4-fpm

Step 3: Install the Most Common PHP Extensions


Most real-world PHP applications- WordPress, Laravel, Magento, Drupal, and custom REST APIs rely on a fairly predictable set of extensions for databases, string handling, image processing, and caching. You can install the most common PHP extensions with:

# apt install -y php8.4-mysql php8.4-pgsql php8.4-sqlite3 \
  php8.4-curl php8.4-mbstring php8.4-xml php8.4-zip php8.4-gd \
  php8.4-bcmath php8.4-intl php8.4-soap php8.4-opcache \
  php8.4-readline php8.4-imagick php8.4-redis php8.4-apcu \
  php8.4-ldap

Note that JSON support is compiled into the PHP core as of PHP 8, so there is no separate php8.4-json package to install. If your application needs something not listed here, you can search Debian’s full extension list with:

# apt search php8.4-

Check the installed version and confirm the extensions loaded correctly:

# php --version
# php -m

The version output should report PHP 8.4.x with the Zend OPcache engine listed underneath it, and php -m should list every module you just installed (curl, gd, mbstring, redis, imagick, and so on).

Step 4: Optimize the php.ini Configuration


You can find the php.ini configuration file in /etc/php/8.4/fpm/php.ini (the CLI copy lives at /etc/php/8.4/cli/php.ini). The default values are intentionally conservative; for a production site you will generally want something closer to this:

# nano /etc/php/8.4/fpm/php.ini

memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120
max_input_time = 300
max_input_vars = 5000

The memory_limit is per-request, not per-worker total. Keep this value (128-256M for most apps) unless specific scripts (imports, report generation) need more memory.

Setting max_execution_time = 300 prevents runaway scripts from holding a worker hostage. If you have legitimately long-running endpoints (exports, batch jobs), don’t raise this globally; you can override per-vhost configuration or run these via CLI/queue workers instead. You can apply the changes with:

# systemctl restart php8.4-fpm

Step 5: Enable and Tune OPcache

OPcache is the most impactful performance setting in PHP. It caches compiled PHP bytecode in shared memory, so the interpreter doesn’t have to reparse and recompile your PHP files on every request. The php8.4-opcache package you installed in Step 3 is enabled by default, but its out-of-the-box limits are sized for small sites. You can edit the configuration file:

# nano /etc/php/8.4/mods-available/opcache.ini

You can set the following values for a typical production application:

opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.max_wasted_percentage=10
opcache.validate_timestamps=1
opcache.revalidate_freq=60
opcache.save_comments=1

opcache.memory_consumption specifies how much shared memory (in MB) is allocated for cached bytecode. 128–256 MB comfortably covers most applications; larger codebases (e.g., big Magento or Drupal installs) may need more.

If your workload is CPU-heavy (image processing, data transformation, computation-heavy APIs), PHP 8.4’s JIT compiler can also help. You can enable it in the same file:

opcache.jit_buffer_size=100M
opcache.jit=tracing

For most standard web applications, the gain from JIT is modest compared to OPcache itself, so treat it as an optional extra rather than a must-have.

Restart PHP-FPM to apply the changes:

# systemctl restart php8.4-fpm

Step 6: Configure Redis as the default session handler

If Redis is not already installed, you can go ahead and install it with:

# apt install redis.

Then, once again, you will need to edit the php.ini file in /etc/php/8.4/fpm/php.ini and set the following values:

session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379"

Restart PHP-FPM to apply the changes:

# systemctl restart php8.4-fpm

Step 7: Tune the PHP-FPM Process Manager

The default FPM pool at /etc/php/8.4/fpm/pool.d/www.conf is set up for a small, generic server. To calculate the pm.max_children, you can use the following formula. First, depending on available RAM (excluding the memory reserved for the system or other processes), a simple way to size pm.max_children would be:

pm.max_children = (available RAM for PHP-FPM – 10% buffer) / (average memory per PHP process)

If you have a PHP-FPM dedicated server with 8GB of RAM with no other, and you measure memory per PHP-FPM process with the command:

# ps --no-headers -o rss,cmd -C php-fpm8.4 | awk '{ sum+=$1; n++ } END { printf "%.1f MB avg over %d procs\n", sum/n/1024, n }'

And you get something like this: 80.3 MB avg over 6 procs

Then you can calculate: pm.max_children = 6300/80

pm.max_children = 78

So from here, you can adjust the other values and edit the configuration file found at:

nano /etc/php/8.4/fpm/pool.d/www.conf

pm = dynamic
pm.max_children = 48
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 500

pm.max_requests = 500 is also worth setting; it recycles each worker after 500 requests, which helps guard against gradual memory leaks in long-running processes.

You can test the configuration and restart:

# php-fpm8.4 -t
# systemctl restart php8.4-fpm

Step 8: Test the Full Setup

echo "<?php phpinfo();" | sudo tee /var/www/html/info.php

Visit http://your_server_ip/info.php in a browser. You should see the full PHP configuration page, which confirms the PHP version, loaded extensions, and active OPcache status.

Important: remove this file once you’ve confirmed everything works, since phpinfo() exposes configuration details you don’t want publicly visible:

rm /var/www/html/info.php

Conclusion

You now have PHP 8.4 running on Debian 13 with the extensions most web applications actually need, along with OPcache, APCu, and PHP-FPM tuned for production use rather than left on their conservative defaults. From here, you can continue your server and application setup.

If you’d rather not manage any of this yourself, you can contact Linux server support specialists who can install, configure, and tune PHP on your VPS.

Leave a Comment