If one file on your WordPress site is worth locking down properly, it is wp-config.php. It holds your database credentials, your security keys, and the switches that decide what the dashboard is allowed to do. This guide shows you how to harden wp-config.php with eight settings, plus the file-level protections that sit around it. Nothing here needs a plugin, and every change takes about a minute once you know where it goes.
Last verified: 26 October 2026, against the official WordPress developer documentation linked at the end of this post.
Before you touch wp-config.php
A single typo in this file can white-screen your whole site, so do the boring steps first. Download a copy of wp-config.php to your computer before you edit it, so you can restore it in seconds if anything goes wrong. Edit it in a proper text editor, not a word processor, and keep the single quotes around every value exactly as they are.
After every edit, check the file for syntax errors before you upload it. If you have SSH access, run this from your site root:
php -l wp-config.php
If that reports “No syntax errors detected”, upload the file and load your homepage and your dashboard. If either one breaks, restore the backup copy and try again with one change at a time. That discipline matters more than any single setting below, because it is how you find out which line caused the problem.
One placement rule applies to every setting in this guide: add your lines above the comment that reads /* That's all, stop editing! Happy publishing. */. Anything you put below that line may not take effect, because WordPress loads its settings right after it.
1. Disable the theme and plugin file editors
define( 'DISALLOW_FILE_EDIT', true );
By default, WordPress lets anyone with a privileged account edit theme and plugin files from inside the dashboard. That is convenient, and it is also a one-click path from a stolen admin session to arbitrary code running on your server. Turning this setting on removes the Theme File Editor and Plugin File Editor from wp-admin entirely. You can still edit files over SFTP or through your host’s file manager, which is where code changes belong anyway.
The official documentation describes this as an extra layer of security if an attacker gains access to a well-privileged user account. It will not stop an attacker who already has file access another way, but it removes the easiest escalation route, and it stops an over-eager user from crashing the site with a bad edit.
2. Consider going one step further: block installs and updates from the dashboard
define( 'DISALLOW_FILE_MODS', true );
This is the stricter sibling of the first setting. It blocks plugin and theme installation and updates from the WordPress admin area, and on its own it also disables the file editors, so you do not need both lines. Only use it if you are happy managing every install and update over SFTP, WP-CLI, or your host’s tools. For a brochure site that rarely changes, that trade is worth it. For a site where editors install plugins weekly, it will cause more friction than security, so skip it and keep setting 1.
3. Force SSL for logins and the admin area
define( 'FORCE_SSL_ADMIN', true );
With this constant set, WordPress serves logins and the whole admin area over HTTPS, so passwords and session cookies are never sent in the clear. If your entire site already forces HTTPS at the server level, this is belt and braces rather than essential, but keep it anyway: it protects you the day a server redirect is misconfigured or removed. Do not use the older name FORCE_SSL_LOGIN — the official documentation says it is deprecated, and FORCE_SSL_ADMIN is the replacement.
4. Make sure debugging stays off in production
define( 'WP_DEBUG', false ); define( 'WP_DEBUG_LOG', false ); define( 'WP_DEBUG_DISPLAY', false );
Debugging is for development, not for a live site. When error display is on in production, visitors — including attackers probing your site — can see PHP warnings, file paths, and database errors that tell them exactly how your site is built. Set all three constants to false on a live site. If you need to diagnose a problem on a live site, log errors to a file temporarily instead of displaying them, and turn debugging off again as soon as you have what you need. Our guide to reading the WordPress debug log walks through that process safely.
5. Rotate your security keys and salts after any incident
Your wp-config.php file contains eight security constants — AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY, and the matching _SALT for each one. WordPress uses them to sign cookies and nonces, so anyone who has ever seen your old keys has a head start on forging a session.
Generate a fresh set from the official WordPress secret-key generator, replace all eight lines in your file, and save it. Every user, including any attacker holding a stolen cookie, is logged out immediately and has to sign in again. Do this after any suspected compromise, after handing a site over to a new owner or developer, and any time your wp-config.php file has been exposed — for example, if it was accidentally committed to a public repository or pasted into a support thread.
You do not need to rotate salts on a schedule if nothing has gone wrong, but there is no downside to doing it after an incident, and it is one of the first steps in most malware cleanups for exactly that reason.
6. Block outbound requests your site does not need
define( 'WP_HTTP_BLOCK_EXTERNAL', true ); define( 'WP_ACCESSIBLE_HOSTS', 'api.wordpress.org,*.wordpress.org' );
WordPress and its plugins make HTTP requests to outside servers all the time: update checks, license checks, embeds, and API calls. A compromised plugin can abuse that same channel to phone data out. Setting WP_HTTP_BLOCK_EXTERNAL to true blocks external URL requests except to localhost and your own blog, and WP_ACCESSIBLE_HOSTS lets you punch specific holes in that block as a comma-separated list of hostnames, with wildcards supported.
Start with api.wordpress.org and *.wordpress.org so core, theme, and plugin updates keep working, then add only the hosts your plugins genuinely need — your payment provider, your email service, your CDN — one at a time, testing after each one. If a plugin suddenly stops working after this change, check its error log for a blocked host before you assume the plugin is broken. This setting is a filter, not a firewall: it reduces what a compromised plugin can reach, but it is not a substitute for removing the compromised plugin.
7. Pin core updates to minor releases
define( 'WP_AUTO_UPDATE_CORE', 'minor' );
Minor WordPress releases are security and maintenance fixes, and the default behaviour is to apply them automatically. Making that explicit in wp-config.php means a future plugin, host setting, or well-meaning edit cannot silently turn it off. Major releases stay manual, so you can test them on staging first — which is the right balance for most sites. If your site is a simple brochure site with no custom code, you can set this to true to allow major releases too, but for anything with custom themes or plugins, keep major updates in your hands.
8. Declare that this is a production site
define( 'WP_ENVIRONMENT_TYPE', 'production' );
WordPress recognises four environment types: local, development, staging, and production. The reason this line matters for security is a quiet default: when the environment type is development and WP_DEBUG is not defined in wp-config.php, WordPress turns debugging on for you. Declaring production explicitly removes that surprise and tells every plugin and theme that reads the environment type to behave as if real visitors are watching — because they are.
The complete copy-paste block
Here are settings 1 and 3 to 8 together, ready to paste above the “stop editing” line. Leave setting 2 out unless you decided you want the stricter dashboard lock, and add your freshly generated salts separately — never copy someone else’s keys.
define( 'DISALLOW_FILE_EDIT', true ); define( 'FORCE_SSL_ADMIN', true ); define( 'WP_DEBUG', false ); define( 'WP_DEBUG_LOG', false ); define( 'WP_DEBUG_DISPLAY', false ); define( 'WP_HTTP_BLOCK_EXTERNAL', true ); define( 'WP_ACCESSIBLE_HOSTS', 'api.wordpress.org,*.wordpress.org' ); define( 'WP_AUTO_UPDATE_CORE', 'minor' ); define( 'WP_ENVIRONMENT_TYPE', 'production' );
Protect the file itself, not just the settings inside it
The settings above are only half the job. The file itself contains your database password in plain text, so protect it at the server level too.
Move it one directory above your web root
WordPress will look for wp-config.php one directory above your install if it is not in the install folder itself. Moving it there means a web server misconfiguration is less likely to expose it, because the file is no longer inside a directory the server is supposed to serve. This adds a little protection on top of the blocks below, and it is optional if your server blocks are in place — but it costs nothing, so do it when you next restructure a site.
Block direct web access to the file
On Apache, add this to the .htaccess file in your WordPress folder:
<Files wp-config.php>
Require all denied
</Files>On Nginx, add this to your server block:
location = /wp-config.php {
deny all;
}After adding either rule, test it by visiting yoursite.com/wp-config.php in a browser. You should get a 403 Forbidden response, not a blank page and definitely not file contents. A blank page is still a pass in the sense that no credentials leaked, but a 403 tells you the rule actually fired.
Tighten the file permissions
chmod 640 wp-config.php
That makes the file readable by its owner and by the web server group, but not by other users on shared hosting. After changing permissions, load your homepage to confirm the site still works — if the web server can no longer read the file, you will know immediately, and you can adjust from there. Never leave this file, or any file, at 777.
Keep it out of version control
Never commit wp-config.php to a public repository, and never paste its contents into a support forum, a chat log, or a screenshot. If your host supports loading secrets from environment variables, use that for the database credentials on staging and production instead of hard-coding them. If a copy has already leaked, rotate the database password and the salts immediately — changing the settings in this guide does not undo an exposure that already happened.
Three things not to do
Do not change the table prefix on a live site and expect the tables to follow. The $table_prefix value only tells WordPress which tables to look for. Changing it on an existing site points WordPress at tables that do not exist, and your site will act as if it has never been installed. A prefix change is an install-time decision, not a hardening shortcut.
Do not leave database repair switched on. WP_ALLOW_REPAIR lets anyone visit the repair page without logging in, which is useful for about ten minutes when a database is corrupt and useless — and dangerous — the rest of the time. Turn it on, repair, turn it off, and verify it is off.
Do not treat these settings as a cleanup. If your site is already compromised, hardening wp-config.php locks the door after the intruder is inside. Clean the infection first, rotate the database password and salts, and only then apply these settings so the next attempt has a harder time.
Verify your work in two minutes
- Homepage loads, and you can sign in to wp-admin.
- Under Appearance and Plugins, the Theme File Editor and Plugin File Editor links are gone.
- Visiting
yoursite.com/wp-config.phpreturns 403 Forbidden. - Core updates still check in: visit Dashboard, then Updates, and confirm it reports your current version without an error.
- No PHP errors or warnings are visible on any public page, even on a page you know used to show a notice.
If any check fails, restore your backup copy of wp-config.php, re-apply the settings one at a time, and re-test after each one. The setting that breaks the check is the one that needs a different value for your host or your plugin set — most often the accessible-hosts list, which needs one more host added.
Further Reading & References
- Editing wp-config.php — WordPress Advanced Administration Handbook (official)
- The Ultimate WordPress Security Guide — WPBeginner
- WordPress Security Checklist: 17 Checks for 2026 — DevDiggers
- WordPress Hardening Checklist (2026) — Domain India
- WordPress Security Hardening: 2026 Checklist — AttoWP
- How to Secure Your WordPress Site: A Complete Security Hardening Guide — DeployBase
- How to Secure wp-admin: 7 Hardening Steps That Actually Matter — HowToShipIt
- WordPress Debug.log: How to Enable It and Read What It Tells You — HowToShipIt


