Resources · Security guides · Security guide
Turn off debug pages and version banners in production
Debug mode turns an error into a map of your app, and some debug tools run code. Turn them off, stop advertising versions, and check from outside.
Check command
curl -sI https://example.com | grep -iE '^(server|x-powered-by):'
Copied.
A stack trace shows file paths, framework versions, SQL and sometimes environment values. Some debug tools go further: Laravel Ignition on old versions (CVE-2021-3129) allowed remote code execution when debug mode was on. Version banners save an attacker the time of guessing what to try.
Laravel and other frameworks
In the production .env:
APP_ENV=production
APP_DEBUG=false
Then rebuild the config cache, because a cached config ignores .env changes:
php artisan config:clear && php artisan config:cache
Check that debug-only packages are not installed in production (composer install --no-dev), and that routes such as /telescope, /horizon, /_ignition and /phpinfo.php are gone or behind authentication.
PHP
In the php.ini used by PHP-FPM (php --ini shows the CLI one; FPM has its own under /etc/php/8.x/fpm/):
expose_php = Off
display_errors = Off
log_errors = On
expose_php = Off removes the X-Powered-By: PHP/8.x header. display_errors = Off keeps errors in the log instead of the page. Restart PHP-FPM afterwards.
nginx and Apache
# http block of nginx.conf
server_tokens off;
# Apache: security.conf
ServerTokens Prod
ServerSignature Off
This shortens Server: nginx/1.30.6 to Server: nginx. It hides the version from casual scans; it does not replace patching.
Check from outside
curl -sI https://example.com | grep -iE '^(server|x-powered-by):'
curl -s https://example.com/this-page-does-not-exist | head -20
The first command should show no PHP version and no web server version. The 404 page should be your app's normal error page, with no stack trace.