Magento’s app/etc/env.php holds your database password, the encryption key used to protect stored data, and other secrets. Automated scanners request it from every Magento store they find, all day. On a correctly set-up store, the request fails. On a misconfigured one, the file downloads.
Test it now
From any computer, not the server itself:
curl -sI https://your-store.com/app/etc/env.php
curl -sI https://your-store.com/.git/config
curl -sI https://your-store.com/composer.json
A 404 or 403 is good. A 200 means the file is public. Also try any backups people may have left in the web folder, such as backup.sql, db.sql.gz or site.zip.
Why it happens
Magento is designed to be served from the pub/ folder. When the web server’s document root points at the Magento root folder instead of pub/, everything in the project becomes reachable, unless the server has rules blocking it.
How to fix it
- Nginx: set the document root to
pub/. Magento’snginx.conf.sampledoes this withroot $MAGE_ROOT/pub;. - Apache: point the virtual host at
pub/, or keep Magento’s own.htaccessfiles, which blockapp/,var/and other folders. - Block hidden folders such as
.gitexplicitly, and move backups out of the web folder.
Test again with curl after the change.
If it was public
Assume it was downloaded. Scanners find these files within hours.
- Change the database password, update
env.php, and restrict database access to the server only. - Change the encryption key with
bin/magento encryption:key:change, then follow Adobe’s guidance to re-encrypt stored data. - Rotate any other secrets in the file, such as API keys and Redis passwords.
- Check for new admin users and unknown files, in case someone already used the access.
Catch it automatically
MageMonitor checks for this every few minutes as part of its Security Center checks for exposed files, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.
