Security & Configuration

PHP Production Configuration and Error Logging

Configure production PHP error handling so diagnostics remain useful to operators without exposing sensitive details to visitors.

Production PHP should record enough diagnostic information for operators without exposing stack traces, filesystem paths, SQL details, or secrets to visitors. The web runtime and CLI runtime may load different configuration files, so settings must be verified in the context where the application actually runs.

Separate display from logging

A common production baseline is:

display_errors = Off
log_errors = On
error_reporting = E_ALL

The destination for error_log should be private, writable by the PHP process, and monitored for disk growth. Do not place logs in a public download directory. Configuration directives may be overridden by PHP-FPM pool settings, per-domain configuration, or hosting-panel controls.

Verify the correct runtime

CLI checks show CLI configuration:

php --ini
php -i | grep -E 'Loaded Configuration|error_log|display_errors'

The website may use another PHP version or handler. Verify web settings through a temporary restricted diagnostic page if required, then delete it. Never leave phpinfo() publicly accessible because it reveals server paths, modules, and environment details.

Handle application errors safely

Catch exceptions at appropriate boundaries, log a correlation identifier, and show visitors a generic error message. Do not log passwords, session IDs, access tokens, or full sensitive request bodies. Include enough context to reproduce the failure: route, operation, timestamp, application release, and sanitized error details.

Rotation and alerting

Ensure PHP-FPM, Apache/Nginx, and application logs have clear ownership and rotation policies. Alert on repeated fatal errors and sudden increases in 5xx responses. A log file that cannot be written can hide the original problem, so monitor both error volume and logging failures.

During development, detailed errors are useful; in production, they belong in protected logs and observability tools. Make the environment mode explicit and ensure a deployment cannot accidentally switch production into debug mode.

Share this page Help other developers discover this resource.