Hosting & Deployment

PHP Production Configuration: A Practical Checklist

Configure PHP for production with safe error handling, sensible resource limits, secure sessions, and environment-specific settings.

Do not display internal errors

For production, errors should be logged rather than displayed to visitors:

display_errors = Off
log_errors = On

Keep logs outside the public document root and restrict access. Do not expose stack traces, filesystem paths, SQL details, or credentials in HTTP responses.

Set resource limits deliberately

Review settings such as:

memory_limit = 256M
max_execution_time = 60
upload_max_filesize = 16M
post_max_size = 20M

These are examples, not universal values. Choose limits based on the application, hosting environment, and expected workload. post_max_size should be greater than or equal to upload_max_filesize.

Secure sessions

Use HTTPS and configure session cookies with Secure, HttpOnly, and an appropriate SameSite policy. Regenerate session IDs after authentication and expire sessions according to the application's risk.

Keep secrets private

Store database credentials and API keys outside the public web root or in a secrets manager. Do not place secrets in source control or diagnostic output.

Verify the effective configuration

CLI and web PHP can load different configuration files. Check the effective settings in both environments, and remove any temporary diagnostic scripts after use.

Monitor and review

Monitor error logs, resource usage, failed jobs, and dependency advisories. Revisit configuration after traffic growth or application changes.