wp-config.php: 9 Hardening Rules You're Probably Breaking
Understanding wp-config.php and Its Importance
The wp-config.php file is one of the most critical components of your WordPress site. It contains sensitive information such as your database credentials, secret keys, and other vital configurations. Ensuring wp-config security is paramount to protect your site from hackers and vulnerabilities.
9 Hardening Rules You Might Be Ignoring
Here are nine essential rules to harden your wp-config.php file that you might be overlooking:
1. Move wp-config.php to a Higher Directory
- By default,
wp-config.phpis located in the root directory of your WordPress installation. - Move it one directory up to prevent direct access from the web.
2. Set Proper File Permissions
- Ensure that the permissions for
wp-config.phpare set to440or400. - This restricts access to the file, allowing only the server to read it.
3. Disable File Editing
- Add the following line to your
wp-config.php:define('DISALLOW_FILE_EDIT', true); - This prevents anyone from editing theme and plugin files from the WordPress dashboard.
4. Use Strong Database Prefixes
- Change the default database prefix from
wp_to something unique likemycustomprefix_. - This makes it harder for attackers to guess your database tables.
5. Set Up Secure Authentication Keys
- Generate unique authentication keys and salts from the WordPress secret key generator.
- Replace the default keys in your
wp-config.phpto enhance security.
6. Limit Access to wp-config.php
- Implement an
.htaccessrule to deny access towp-config.php. - Example rule:
deny from all
7. Disable XML-RPC if Not Needed
- If you don’t use XML-RPC, disable it by adding:
add_filter('xmlrpc_enabled', '__return_false'); - This helps prevent brute force attacks and DDoS attacks.
8. Regularly Update Your WordPress Installation
- Keep your WordPress core, themes, and plugins updated to patch known vulnerabilities.
- Regular updates can prevent exploitation of outdated components.
9. Use a WordPress Security Plugin
- Consider using a security plugin that offers features like firewall protection, malware scanning, and login security.
- Many plugins can help automate security checks and hardening measures.
Conclusion
Securing your wp-config.php file is a crucial step in protecting your WordPress site. By following these nine hardening rules, you can significantly reduce the risk of your site being hacked or compromised.
Where to Start
If you're unsure about the security of your WordPress site, consider getting a comprehensive online presence audit. A professional audit can identify vulnerabilities and help you implement necessary security measures.
Want this done for you — automatically?
The WP-Sec WordPress audit checks everything in this article against your actual business: Google reputation, local rankings, website health, conversion readiness and AI search visibility — ranked by revenue impact.
Get my audit — $40 →