{"id":18928,"date":"2026-10-21T20:17:42","date_gmt":"2026-10-21T17:17:42","guid":{"rendered":"https:\/\/www.hyyat.com\/knowledgebase\/protect-wp-config\/"},"modified":"2026-10-21T20:17:53","modified_gmt":"2026-10-21T17:17:53","password":"","slug":"protect-wp-config","status":"publish","type":"docs","link":"https:\/\/www.hyyat.com\/en\/knowledgebase\/protect-wp-config\/","title":{"rendered":"How to Protect wp-config.php in WordPress: 7 Steps to Secure Your Most Important File"},"content":{"rendered":"<div class=\"hkb\" dir=\"ltr\">\n<div class=\"hkb-tldr\"><b>In short<\/b>wp-config.php is the most important file in a WordPress site: it holds the database name, user, password and the keys that encrypt login sessions. Anyone who reads it can reach all your site\u2019s data. Protect it with 440 or 400 permissions, block browser access, change the security keys after any breach, disable the file editor and delete any copy saved with another extension.<\/div>\n<figure class=\"hkb-fig\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.hyyat.com\/zasogooh\/2026\/10\/hkb-wp-config.webp\" alt=\"The WordPress configuration file wp-config.php and a protective lock\" width=\"1200\" height=\"630\" loading=\"lazy\" \/><\/figure>\n<h2>What does the file contain?<\/h2>\n<div class=\"hkb-cards\">\n<div class=\"hkb-card\"><i>DB<\/i><b>Database credentials<\/b><span>Database name, user, password and host.<\/span><\/div>\n<div class=\"hkb-card\"><i>K<\/i><b>Security keys<\/b><span>AUTH_KEY and the other keys that encrypt login cookies.<\/span><\/div>\n<div class=\"hkb-card\"><i>\u2699<\/i><b>Site settings<\/b><span>Table prefix, debug mode, update and memory settings.<\/span><\/div>\n<\/div>\n<h2>7 steps to protect it<\/h2>\n<ol class=\"hkb-steps\">\n<li><b>Set permissions to 440 or 400:<\/b> In the cPanel File Manager select the file, then \u201cChange Permissions\u201d. On our servers PHP runs as the account owner, so the site can still read it. Read <a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/secure-file-permissions\/\">secure file permissions<\/a>.<\/li>\n<li><b>Block browser access:<\/b> Add the rule below to your main <code>.htaccess<\/code> file.<\/li>\n<li><b>Change the security keys after any breach:<\/b> Generate new keys from the official WordPress generator <code>api.wordpress.org\/secret-key\/1.1\/salt\/<\/code> and replace the old ones. This logs everyone out, including the attacker.<\/li>\n<li><b>Disable the dashboard file editor:<\/b> Add <code>define('DISALLOW_FILE_EDIT', true);<\/code> so anyone who gets into your dashboard cannot edit theme and plugin files from it.<\/li>\n<li><b>Turn debug mode off:<\/b> Set <code>WP_DEBUG<\/code> to false on a live site so file paths and errors are not shown to visitors.<\/li>\n<li><b>Delete exposed copies:<\/b> A file such as <code>wp-config.php.bak<\/code> or <code>wp-config.old<\/code> is not run as PHP, so it may be readable as plain text with your password. Remove any copy like this from the site folder.<\/li>\n<li><b>Use a strong database password:<\/b> If you suspect the file leaked, change it in cPanel and then update it in the file.<\/li>\n<\/ol>\n<pre class=\"hkb-code\">&lt;Files wp-config.php&gt;\n  Require all denied\n&lt;\/Files&gt;<\/pre>\n<div class=\"hkb-note w\"><b>Before editing:<\/b> save a copy of the file on your computer. A small mistake stops the whole site, and the copy restores it in seconds.<\/div>\n<p>Can you move the file outside the site folder? WordPress also looks for it one folder up, but this does not suit every case, such as sites in subfolders. 440 permissions and blocked access are enough for most sites.<\/p>\n<div class=\"hkb-hh\">\n<h2>How Hyyat Host protects your site<\/h2>\n<ul>\n<li><strong>CloudLinux<\/strong> isolates every account, so other sites on the server cannot read your files.<\/li>\n<li><strong>ModSecurity<\/strong> and <strong>Imunify360<\/strong> rules block known requests that try to read configuration files.<\/li>\n<li><strong>ImunifyAV<\/strong> scans files daily and detects malicious code added to WordPress files.<\/li>\n<\/ul>\n<\/div>\n<h2>Frequently asked questions<\/h2>\n<div class=\"hkb-faq\">\n<details>\n<summary>Will 400 permissions break my site?<\/summary>\n<p>Not on Hyyat Host servers, because PHP runs as the account owner. If an error appears after the change, try 440 or 644.<\/p>\n<\/details>\n<details>\n<summary>When should I change the security keys?<\/summary>\n<p>After any breach or leaked admin password, or when a staff member with access leaves. It only logs everyone out and does not harm the site.<\/p>\n<\/details>\n<details>\n<summary>Can anyone read the file from a browser?<\/summary>\n<p>Usually not, because the server runs it as PHP and does not show its contents. The real risk is copies with other extensions or PHP failing, so add the block rule.<\/p>\n<\/details>\n<\/div>\n<div class=\"hkb-rel\"><b>Related guides<\/b><\/p>\n<ul>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/secure-file-permissions\/\">Secure File Permissions for Your Website: When to Use 644 and 755, and Why to Avoid 777<\/a><\/li>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/security-headers\/\">Security Headers: What They Are and How to Add Them to Your Website<\/a><\/li>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/protect-website-from-hacking\/\">How to Protect Your Website from Hacking: 10 Practical Steps<\/a><\/li>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/hacking-tools-c99-shell\/\">What Is a C99 Shell? How It Gets In and How to Find and Remove It<\/a><\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.hyyat.com\/en\/kb\/website-protection\/\">All website security guides \u2192<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In shortwp-config.php is the most important file in a WordPress site: it holds the database name, user, password and the keys that encrypt login sessions. Anyone who reads it can reach all your site\u2019s data. Protect it with 440 or 400 permissions, block browser access, change the security keys after any breach, disable the file [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"_templately_pack_id":"","_templately_imported_at":"","_templately_source":"","_templately_import_session_id":"","footnotes":""},"doc_category":[2744],"doc_tag":[],"class_list":["post-18928","docs","type-docs","status-publish","hentry","doc_category-website-protection"],"year_month":"2026-10","word_count":559,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"ahmed fathy","author_nicename":"ahmed-fathy","author_url":"https:\/\/www.hyyat.com\/en\/author\/ahmed-fathy\/"},"doc_category_info":[{"term_name":"Website Security","term_url":"https:\/\/www.hyyat.com\/en\/kb\/website-protection\/"}],"doc_tag_info":[],"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/docs\/18928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/comments?post=18928"}],"version-history":[{"count":0,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/docs\/18928\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/media?parent=18928"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/doc_category?post=18928"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/doc_tag?post=18928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}