# PHP Hardening Checklist: The php.ini and Server Settings That Matter

By PHP Patch Assurance · Last updated: 2026-11-20

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.

## Hide the fingerprints

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](/guides/version-hidden).

## Errors: log them, never show them

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.

## Turn off the dangerous conveniences

`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.

## Lock down sessions

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.

## Uploads and the filesystem

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.

## Verify every setting took effect

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](/guides/mod-php-vs-php-fpm)), confirm with `php -i` on the server or a protected phpinfo page, and re-run the [free scan](/scan): the version header should be gone.

## Frequently asked questions

### Does hardening replace patching?

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.

### Will disable_functions break my site?

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.

### Where do these settings go?

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.
