Database passwords, application keys and provider tokens should not be downloadable website files. Directory layout and deployment controls should keep them outside public delivery paths.
IN THIS ARTICLE
01 Prepare for the change
Identify the active document root and every place the application loads secrets. Check backups, old environment files and deployment archives as well as the current configuration file.
02 Move runtime secrets out of a public document root
Move secrets into the hosting platform’s protected environment or an appropriately permissioned private configuration location supported by the application.
Keep the web document root limited to the framework’s public entry files and assets. Update application paths through the supported deployment configuration.
Remove public backup copies, editor leftovers and old archives containing credentials after securing a proper private recovery copy.
Test direct requests for likely configuration paths and confirm they do not disclose contents. Use server access rules as an additional control where appropriate.
If a secret was exposed, rotate it and review access. Moving the file does not invalidate copies already obtained.
03 Confirm the expected result
Confirm the app still starts and that ordinary visitors cannot retrieve configuration or backup files. Check the final release artifact and future deployment process for recurrence.
04 Example: rotate an application secret without publishing it
Identify every process that uses the secret before changing it. A website, queue worker and scheduled task may run under separate environment configurations even though they belong to one application.
- Create or obtain the replacement secret through the provider's approved process.
- Update the intended production secret store or environment setting without committing the value to Git.
- Restart or reload the relevant processes as required by the application's deployment model.
- Test a safe operation and confirm the replacement works before retiring the old value, where the provider supports that sequence.
Can I check the value by printing the whole environment?
Avoid exposing all environment variables in a browser response or support ticket. Test whether the required setting is present without printing the secret itself. Remove temporary diagnostic code immediately after use.
If the value was already exposed, treat removal and rotation as separate tasks. Deleting one file or log entry does not make a copied credential safe again. Tell us the hosting capability you need and the relevant redacted error when requesting help. Keep the actual credential in your approved private storage.
If the change does not work
A denied current .env file does not prove an old archive or alternate filename is protected. Review the full public directory rather than testing one path only.
05 A common question
Is a filename beginning with a dot automatically private?
No. Visibility depends on the server and access configuration. Use a safe directory layout and verify the actual HTTP behavior.