By PHP Patch Assurance · Last updated: 2026-11-20 · Plain-text version
Hardening is the set of configuration changes that shrink what an attacker can learn and what a bug can reach, independent of patching. None of it fixes a vulnerability; all of it reduces the value of one. The settings below are the production baseline for a PHP site, set in php.ini, the PHP-FPM pool config, or a per-directory .user.ini, depending on the SAPI.
Set expose_php = Off so responses stop advertising the PHP version in the X-Powered-By header. That does not make a vulnerable version safe — it removes the free targeting information scanners use to pick which sites to try first. The full picture is in the version-hidden guide.
In production: display_errors = Off, log_errors = On, and error_log pointed at a file outside the web root. A displayed error leaks paths, SQL and credentials to whoever triggered it; a logged error tells you the same things privately. Add zend.exception_ignore_args = On so stack traces in logs stop recording function arguments, which routinely include passwords and tokens.
allow_url_include = Off — remote file inclusion should be impossible, not merely unused. Review disable_functions: most content sites never need exec, shell_exec, passthru, popen or proc_open from the web SAPI, and disabling them limits what a compromised script can do next. Treat that list as a seatbelt, not a wall: it slows an attacker, it does not stop one. Behind nginx, set cgi.fix_pathinfo = 0 unless you know you need it, so a crafted path cannot make the server execute an uploaded file as PHP.
Set session.cookie_httponly = 1, session.cookie_secure = 1 on HTTPS sites, session.cookie_samesite = Lax, and session.use_strict_mode = 1 so the server refuses session ids it did not issue. Together these close the standard session-theft and session-fixation paths without touching application code.
If the site does not accept uploads, set file_uploads = Off and remove the question entirely. If it does, store uploads outside the web root — or in a directory where the server will not execute scripts — and treat open_basedir as a useful tripwire that confines PHP to the directories it actually needs.
php.ini edits fail silently when they land in the wrong file for the SAPI in use — the CLI, FPM and Apache configs are different files. After restarting the right service (see which SAPI runs your site), confirm with php -i on the server or a protected phpinfo page, and re-run the free scan: the version header should be gone.
Check your site free Patch service
This guide pairs with the free scan.
No. Hardening reduces what an attacker learns and reaches; the vulnerability is still there. An end-of-life branch with perfect php.ini settings is still end-of-life. Patch first, harden second, do both.
It can: backup tools, image processors and some plugins shell out. Apply the list in staging, exercise the site, and read the error log — a disabled function fails loudly in the log, which is exactly where you want to discover it.
The php.ini for the SAPI that serves the site: the FPM pool config for PHP-FPM, the Apache PHP config for mod_php, or a .user.ini in the site root where the host only allows per-directory settings. Verify with php -i under the same SAPI, not the CLI.