Exposed Files

wp-config.php backups: the WordPress classic

One file holds the keys to a WordPress site

Every WordPress install keeps its most sensitive settings in a single file: wp-config.php. Inside are the database host, username and password, plus the secret authentication keys WordPress uses to sign cookies. Get that file and you essentially have the site's database. The good news is that the live file is safe by design. The bad news is the backup copy sitting next to it, which usually is not.

Why the live file is fine but a backup is not

This is the crux of the whole issue. When a browser requests wp-config.php, the server hands it to PHP, which executes it and returns whatever the script outputs — which is nothing visible. You never see the source. The credentials stay hidden because the file is run, not displayed.

A backup copy breaks that. Rename it to wp-config.php.bak, wp-config.old, wp-config.php~ or wp-config.php.save and the server no longer recognises it as PHP. It treats it as a plain text file and serves the raw contents — database password and all — to anyone who asks for that URL.

How these backups appear

Nobody creates these on purpose to leak. They show up as a side effect of normal work:

  • An editor that auto-saves a .save or ~ copy when you edit the file on the server.
  • A manual cp wp-config.php wp-config.php.bak before making a change, then forgotten.
  • A migration or plugin that drops a copy somewhere reachable.
  • An archived .zip or .tar.gz of the site left in the web root.

Every one of these leaves a readable copy where the original was protected.

Bots know exactly what to ask for

This is one of the most predictable exposures on the web, which is why automated scanners love it. They do not need to find a link — they request a fixed list of well-known backup names directly. wp-config.php.bak, wp-config.txt, wp-config.php.old and similar are all on that list, checked on countless sites every day. A backup left reachable is found by automation, not by luck.

How to fix and prevent it

  • Delete backup copies of wp-config.php from the web root. If you need a backup, store it outside the served directory.
  • Rotate the credentials if a copy was ever reachable: change the database password and regenerate the WordPress secret keys, since you must assume they leaked.
  • Avoid editing config on the server with editors that leave temp copies; edit locally and deploy.
  • Keep archives out of the web root — never leave a site .zip where it can be downloaded.

Check for the files you forgot

The whole problem with backup files is that nothing links to them — your site looks completely normal while the copy sits at a guessable URL. An automated scan requests the backup and config paths a bot would and tells you if any are reachable. Scan your site and find the leftover files before someone else does.

Related reading

FAQ

Why is wp-config.php safe but a backup of it dangerous?
The live wp-config.php is executed by PHP, so its source is never shown. A backup like wp-config.php.bak has a different extension, so the server treats it as plain text and serves the raw contents — including your database password — to anyone who requests it.
Bots requested my wp-config backup — what should I do?
Assume the credentials leaked. Delete the backup from the web root, then change your database password and regenerate the WordPress secret authentication keys. Check for any unexpected admin users or changes while you are at it.
How do I stop these backup files appearing?
Avoid editing config directly on the server with editors that leave temp or .save copies — edit locally and deploy instead. Keep any deliberate backups and site archives outside the web root so they cannot be served.