Security considerations for env vars
Published
Updated
🔐
Keep secrets out of version control.
Environment variables store sensitive data like database passwords and API keys. Keep env vars out of version control and public access to prevent unauthorized access.
Don't deploy a .env file
A .env file with secrets holds them in plain text. Keep it out of git and don't upload it. In the web root, without a rule that blocks it, anyone can download it from example.com/.env. Set the production values in the dashboard.
Don't expose phpinfo
phpinfo() prints every environment variable, the database password included. Remove phpinfo pages from production. Debug toolbars and profilers can show the same data, keep them off in production.
Keep secrets out of logs and error pages
Error pages in debug mode show ENV vars as well. Keep debug mode off in production, such as APP_DEBUG=false in Laravel or CRAFT_DEV_MODE=false in Craft CMS.