Hardening guide

php.ini security settings: a hardening checklist for 2026

Short answer

Start from php.ini-production, not the development file and not an empty config. Then switch off what you don’t use (expose_php, session upload progress, URL includes), log errors somewhere you chose on purpose, harden session cookies, and lock the important values with php_admin_value so applications can’t change them back.

On this page

Why php.ini settings mattered so much this year

Patching PHP is the fix for every bug PHP shipped in 2026. Settings are what decide how bad things get in the days between a disclosure and your upgrade. Look at this year’s advisories and the same few lines in php.ini keep coming up. PHP2Shell in October and two of the critical bugs in the November release involved session upload progress. A PHP 8.5 bug depended on whether exception arguments are kept in backtraces. Another was reported to depend on startup warnings landing in a log file.

None of the settings below replaces an upgrade. They’re the ones worth getting right once, on every server, so the next advisory finds less to work with.

Start from the right base file

PHP ships two templates: php.ini-production and php.ini-development. Without any php.ini, PHP uses its built-in defaults, which are friendly to development: errors are displayed in the page, and argument values are kept in stack traces.

That third case is more common than it sounds. The official Docker php image ships php.ini-production and php.ini-development under $PHP_INI_DIR and uses neither until you copy one into place. Its documentation shows:

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

If your Dockerfile doesn’t have a line like that, your containers are probably running on built-in defaults. One of November’s PHP 8.5 bugs (CVE-2026-129474) needed exactly that: PHP’s advisory says php.ini-production blocks the demonstrated path, while the development file and no file at all don’t.

To see which file the web runtime actually loads (the CLI often reads a different one):

php-fpm8.3 -i | grep -E "Loaded Configuration File|Scan this dir"   # PHP-FPM
php --ini                                                             # CLI only

With Apache mod_php, a temporary phpinfo() page served through the site shows “Loaded Configuration File”. Delete it as soon as you’ve read it.

Lock the values applications shouldn’t change

A setting in php.ini is a default. Depending on its scope, an application can override it with ini_set(), a .user.ini file or an Apache php_value line. session.upload_progress.enabled, for example, can be set per directory, which is why PHP’s 21 October advisory warned not to rely on ini_set() or FPM .user.ini files for it.

Values set with php_admin_value or php_admin_flag in a PHP-FPM pool, or in the Apache server or virtual host config, can’t be changed by the application:

; /etc/php/8.3/fpm/pool.d/www.conf (one block per pool)
php_admin_flag[session.upload_progress.enabled] = off
php_admin_flag[zend.exception_ignore_args] = on
php_admin_value[session.serialize_handler] = php
# Apache with mod_php, in the vhost or server config
php_admin_flag session.upload_progress.enabled off

Use this for anything security-relevant that you’ve decided on centrally. Restart PHP-FPM or Apache afterwards. A reload can leave old workers running with the old values.

Stop advertising, and log on purpose

expose_php = Off
display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = /var/log/php/error.log   ; or: error_log = syslog

expose_php = Off removes the X-Powered-By header that announces your exact PHP version to every visitor and scanner. It fixes nothing, but there’s no reason to publish your patch level. Both templates leave it On, so this is one you change yourself.

display_errors must be Off in production. Error messages leak paths, queries and sometimes credentials. Log them instead, to a destination you picked: a file that only the PHP user can write, or syslog.

This year added a reason to care where errors go. The timezone cache bug, CVE-2026-129496, was reported by Semgrep and others to need a startup or early diagnostic written to a file-based error_log. Red Hat’s suggested mitigation is error_log = syslog plus fixing the warnings. The lasting lesson is simpler: a production server shouldn’t print startup warnings at all. Look for lines containing PHP Startup or in Unknown on line 0 in your log and fix their causes.

Set date.timezone explicitly

date.timezone = UTC

Use your own zone if you prefer, but use a valid one. An invalid value is a classic source of the startup warnings mentioned above, and an explicit setting means the server’s behaviour doesn’t change when someone edits /etc/timezone.

Session settings

Sessions were the busiest area of PHP security this year. These are the settings to check:

session.use_strict_mode = 1
session.use_only_cookies = 1
session.cookie_httponly = 1
session.cookie_secure = 1
session.cookie_samesite = Lax
session.upload_progress.enabled = 0

session.use_strict_mode = 1 makes PHP reject session IDs it didn’t create, which closes off session fixation. It’s off by default. cookie_httponly keeps JavaScript away from the session cookie, cookie_secure keeps it off plain HTTP (set it only if the whole site runs on HTTPS), and cookie_samesite = Lax stops most cross-site requests from carrying it. use_only_cookies = 1 is already the default; leave it that way so session IDs never travel in URLs.

session.upload_progress.enabled = 0 is the one that mattered this autumn. It was On by default for years and sat on the attack path of PHP2Shell, CVE-2026-115560 and phpAfterShell (CVE-2026-126714). Several analyses report that the November releases switch it off by default, but an explicit On in your config still wins. Very few applications use it. If yours has an upload progress bar that reads from the session, test that page after the change.

One serializer per session store. CVE-2026-115560 needed the writer and the reader of the same session data to use different session.serialize_handler values. PHP’s advisory notes that this can happen across pools or processes, not just through ini_set() in one script. If several sites, pools or CLI scripts share a session directory or Redis database, give them the same handler, or better, separate stores. Separate session.save_path directories per site are good practice on shared servers anyway.

Errors and backtraces in PHP 8.5

zend.exception_ignore_args = On
; PHP 8.5 and later only:
fatal_error_backtraces = On   ; or Off, see below

zend.exception_ignore_args = On keeps argument values out of stack traces. That’s sensible on its own, since arguments can include passwords and tokens that then end up in logs. It’s also PHP’s workaround for CVE-2026-129474 on PHP 8.5 before 8.5.13. php.ini-production already sets it.

fatal_error_backtraces is new in PHP 8.5 and On by default: fatal errors now come with a backtrace. Setting it Off is PHP’s workaround for CVE-2026-129182 and an alternative workaround for CVE-2026-129474. Once you’re on 8.5.13, keeping it On is fine as long as zend.exception_ignore_args is On too. Note that display_errors = Off doesn’t stop PHP from building the backtrace, so it isn’t a substitute.

Remote files: allow_url_include and allow_url_fopen

allow_url_include = Off
allow_url_fopen = Off   ; only if your code doesn't fetch URLs this way

allow_url_include lets include and require load code from a URL. It’s Off by default and deprecated since PHP 7.4. If it’s On anywhere, find out why.

allow_url_fopen is On by default and lets file_get_contents(), fopen() and friends open http:// and ftp:// URLs. Two of November’s fixes lived in exactly those wrappers: mixed-case HTTPS URLs sent in plaintext and a CPU burn from folded headers. If your application uses cURL (or a client built on it) for all outbound HTTP, switching allow_url_fopen off removes that code path entirely. Test first: plenty of plugins and libraries still fetch URLs with file_get_contents().

open_basedir and disable_functions: useful, not walls

open_basedir = /var/www/example.com/:/tmp/
disable_functions = exec,passthru,shell_exec,system,proc_open,popen

open_basedir limits which paths PHP file functions can touch. disable_functions removes functions from the runtime. Both make life harder for an attacker who already has a foothold, and both have had bypasses over the years, so treat them as speed bumps rather than a security boundary. Neither would have stopped the November bugs, which sit inside PHP itself.

Check before you disable anything. Composer, image tools, backup plugins and queue workers often need proc_open or exec. Breaking them quietly is worse than not setting the option.

Size and time limits

memory_limit = 256M
max_execution_time = 30
max_input_time = 60
post_max_size = 32M
upload_max_filesize = 32M
max_input_vars = 1000

Set these to what your application needs, not to the largest value anyone ever asked for. post_max_size must be at least upload_max_filesize. Never set memory_limit = -1 on a web server. Tight request limits were one of the interim measures during PHP2Shell, and a sensible max_input_vars (1000 is the default) keeps huge form submissions from tying up workers.

If you run php-cgi: cgi.fix_pathinfo

Most servers run PHP-FPM or Apache’s mod_php. If yours runs the php-cgi binary, for example PHP on Windows behind IIS, upgrade for CVE-2026-129538, which Semgrep reported depends on cgi.fix_pathinfo=1, the default. Changing that setting alters how PATH_INFO and SCRIPT_FILENAME are built and can break routing, so test it on a copy rather than flipping it in production. Moving to PHP-FPM is the cleaner long-term answer.

Copy-paste starting point

Put this in a file that loads after the main php.ini, such as /etc/php/8.3/fpm/conf.d/99-hardening.ini (adjust the path and version), then restart PHP-FPM:

; Base: php.ini-production. Review each line against your application.
expose_php = Off
display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = syslog
date.timezone = UTC

zend.exception_ignore_args = On
allow_url_include = Off

session.use_strict_mode = 1
session.use_only_cookies = 1
session.cookie_httponly = 1
session.cookie_secure = 1
session.cookie_samesite = Lax
session.upload_progress.enabled = 0

Then confirm from the web runtime, not the CLI:

sudo systemctl restart php8.3-fpm
php-fpm8.3 -i | grep -E "expose_php|display_errors|upload_progress.enabled|exception_ignore_args"

Lock the session and backtrace lines with php_admin_flag in each pool, as shown above, if more than one team or application shares the server. The PHP-FPM hardening checklist covers the pool side: listeners, the status page, catch_workers_output and connection reuse.

If you’re mid-upgrade and want to know which of November’s bugs your current settings leave open, run the seven quick checks. Rather not do it yourself? We patch and verify one server, from €79.

Shayan Abbas writes these PHP security guides from the official advisories and vendor guidance listed below, and updates them when those change. About this site

Sources

  1. php.net: Description of core php.ini directives
  2. php.net: Session security ini settings
  3. php.net: Session runtime configuration
  4. php.net: Error handling runtime configuration
  5. php.net: PHP-FPM configuration (php_admin_value, php_admin_flag)
  6. PHP: GHSA-658j-r8rw-q6mx: session serializer mismatch (CVE-2026-115560)
  7. PHP: GHSA-8mjj-2r7p-4hg2: use-after-free in magic method backtraces (CVE-2026-129474)
  8. Red Hat: RHSB-2026-020: PHP vulnerabilities and mitigations (error_log, upload progress)
  9. Docker Hub: official php image (configuration and php.ini templates)

Know about the next critical PHP bug first

Short, plain-English alerts when a serious PHP vulnerability or fix lands — with what to patch and how. About two emails a month.