php.ini Security Audit Guide
Last updated:
A php.ini audit is a static review of a PHP server's configuration file — php.ini — checked line by line against known-good practice, without running PHP. The file is small, usually a few dozen settings, but it decides whether errors leak paths to visitors, whether a file-inclusion flaw becomes remote code execution, which functions any script can call, and whether a stolen cookie ends a session. This guide walks through the settings that matter, the display-versus-log trade-off, session hardening, and the mistakes that show up again and again — then shows you how to run the same audit yourself with the php.ini Auditor.
What a php.ini audit actually checks
A config audit reads the file the way PHP reads it: as a list of settings, one per line. php.ini uses directive = value lines — display_errors = Off, memory_limit = 128M — with ; and # comments, quoted values, and [Section] headers that group settings without changing what they mean. Because a setting that is simply absent leaves the compiled-in default in force, an audit checks absence as carefully as presence: the line you never wrote can be the one that matters most.
The checks fall into four families. Error handling: what errors reveal, and where they go. Code execution: what a script is allowed to do — include remote files, run shell commands, read outside its own tree. Sessions: how the cookie is protected and whether session IDs can be fixated. And resource limits: how much memory, time and input one request may consume. The php.ini Auditor runs these rules and scores the result from 0 to 100; the same audit family covers Apache and MySQL/Postgres configs.
The settings that decide your security posture
Five settings do most of the work. display_errors = On prints errors — paths, SQL fragments, stack traces — to anyone who triggers one. allow_url_include = On turns a file-inclusion flaw into remote code execution: an attacker includes a file from their own server and PHP runs it. A missing disable_functions means every script can call exec, shell_exec and system, so one injection becomes a shell. No open_basedir means a script can read files anywhere the server user can — other sites on the same host, /etc/passwd, the config itself. And session.cookie_httponly = 0 hands the session cookie to any JavaScript that runs on the page.
Then come the quieter ones. expose_php = On advertises the PHP version in every response header, which is free reconnaissance for an attacker choosing an exploit. log_errors = Off means errors vanish entirely — hidden from visitors and lost to you as well. session.use_strict_mode = 0 accepts session IDs the server never created, which is how session fixation works. memory_limit = -1 and max_execution_time = 0 remove both brakes at once, so one slow request can hold a worker — or the whole server — forever. And the three removed directives — register_globals, magic_quotes_gpc, safe_mode — set to On tell you something else entirely: the install is ancient, because no supported PHP has had them since 5.4. That reading is the audit.
The error-handling trade-off: display vs log
PHP offers two destinations for an error, and the config picks between them. display_errors = On prints it to the visitor — useful on a development machine, where you are the only visitor. log_errors = On with error_log set writes it to a file only you read. Production wants the second, always: an error message is a map of your application — file paths, query fragments, function names — and there is no reason to hand that map to strangers.
error_reporting is where the trade-off hides. E_ALL sees everything; -1 is the same value by another name. E_ALL & ~E_DEPRECATED drops only deprecation notices, which is fine. But a level that excludes E_ERROR or E_WARNING — the common E_ALL & ~E_DEPRECATED & ~E_WARNING in the demo below — is blind to the errors that matter most, and no amount of logging fixes a level that filtered the error out before it reached the log. Set E_ALL and filter at the log, not at the source — and remember that log_errors = Off with display_errors = Off is the worst of both: errors hidden from visitors and lost to you as well.
Session hardening: strict mode, cookies-only, and the three flags
A session is a cookie with an ID in it, and the ID is the whole secret — whoever holds it is logged in as that user. session.use_strict_mode = 1 makes PHP accept only IDs it created, which closes session fixation: an attacker can no longer hand a victim an ID they chose. session.use_only_cookies = 1 keeps the ID out of URLs, where it would leak through Referer headers, proxy logs and shared links. Together they are two lines, and they remove the two cheapest ways to steal a session.
Then the three cookie flags. session.cookie_httponly = 1 hides the cookie from JavaScript, so a cross-site scripting hole cannot read it — there is no legitimate reason to leave it Off. session.cookie_secure = 1 sends the cookie over HTTPS only; without it, the cookie crosses the wire in cleartext on any plain-HTTP request. session.cookie_samesite — Lax by default since PHP 7.3, Strict if you set it — decides whether the browser sends the cookie on cross-site requests at all. The remaining two are housekeeping: session.save_path should point at a directory only this application can read, especially on shared hosting, and session.gc_maxlifetime above a day means a stolen session stays usable for a day or more.
The five mistakes the auditor flags most
Across real-world configs, the same five findings recur. First, display_errors = On in production — the classic leak, paths and stack traces handed to anyone who triggers an error. Second, allow_url_include = On — the one that turns a file-inclusion flaw into remote code execution. Third, no disable_functions at all — every script one injection away from a shell. Fourth, post_max_size below upload_max_filesize — uploads at the cap always fail, and the error message blames the file instead of the config. Fifth, the removed directives set to On — register_globals, magic_quotes_gpc, safe_mode — which say the install predates PHP 5.4 and has not been touched since.
The demo config below manages most of them in 25 lines, plus a few extras: session cookies without HttpOnly or Secure, strict mode off, unlimited memory and runtime, and a 20M upload cap with an 8M post cap. The auditor scores it 14 out of 100, band Poor. Its hardened twin — same shape, every finding fixed — scores 100.
What a static audit cannot see — and auditing yours in five minutes
A static audit reads text, and its limits are the limits of text. It cannot see the values PHP is actually running with — a setting in the file can be overridden at startup, by a per-directory .user.ini, or at runtime with ini_set(), so check phpinfo() or ini_get() on the server for the live truth. It cannot see the PHP version or whether it is still supported, loaded extensions, the SAPI (CLI vs FPM vs mod_php), or real server exposure — a public-looking setting behind a firewall is a different risk from the same line on a public server. And it cannot see the code itself: a perfect php.ini does not fix an application that includes user input.
To audit yours in five minutes: copy the config (or the one file you care about), paste it into the php.ini Auditor — it runs entirely in your browser, and the config is never uploaded, which matters because a config names paths and session storage you do not publish. Fix the errors first (display_errors On, allow_url_include On, the removed directives, post_max_size below upload_max_filesize), then the warnings, then work through the infos as a list of defaults worth setting explicitly. Export the findings CSV if you want the checklist in a ticket. Then check the live values on the server — phpinfo() will show you what PHP is actually running with — because a clean php.ini is only half the story.
The broken demo config
; Demo php.ini — deliberately broken. Do not deploy.
[PHP]
expose_php = On
display_errors = On
display_startup_errors = On
log_errors = On
error_reporting = E_ALL & ~E_DEPRECATED & ~E_WARNING
allow_url_fopen = On
allow_url_include = On
file_uploads = On
upload_max_filesize = 20M
post_max_size = 8M
disable_functions =
open_basedir =
max_execution_time = 0
memory_limit = -1
max_input_vars = 100
register_globals = On
magic_quotes_gpc = On
safe_mode = On
date.timezone =
[Session]
session.cookie_httponly = 0
session.cookie_secure = 0
session.use_strict_mode = 0
session.use_only_cookies = 0
session.gc_maxlifetime = 172800
session.save_path =