Harden WordPress Files After the PHP RCE: 6 Checks
Patch PHP first, then audit WordPress permissions and file-editor access. Keep wp-config backups private and apply server rules only after checking your setup.
The short answer
Patch the October 2026 PHP flaws in PHP first. Then review WordPress file ownership and permissions, protect wp-config.php, disable the dashboard editor, and apply web-server rules only where they fit. Keep configuration copies private and outside every web-served root; avoid blind recursive chmod. These controls reduce exposure but do not replace a PHP patch or incident response.

Reading options
On this page
Patch PHP first. Then spend 30 minutes on six file-level checks: correct folder and file permissions, a locked-down wp-config.php, the dashboard file editor switched off, and two small .htaccess blocks. None of this fixes the PHP flaw, but it makes life harder for anyone who gets a foothold on your site.
On 21 October 2026 the PHP project shipped PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35 to fix two critical bugs, CVE-2026-109618 and CVE-2026-109619, that "can allow unauthenticated remote code execution". That means someone could run their own code on a server without logging in. WordPress.org said the same day that "No WordPress update is required or planned for these issues". The fix lives in PHP, not in WordPress.
By the end of this guide you will have checked the file-permission model, protected wp-config.php, and tested web-server restrictions that fit your installation. Record the original settings and allow time for verification and recovery; an instant rollback is not guaranteed.
Heads up: this guide does not replace updating PHP. If you have not done that yet, read our companion post on patching PHP after the October 2026 security release first, or ask your host which PHP version your site runs right now.
What "hardening WordPress files" actually means
Hardening means removing easy wins for an attacker. You are not adding a new security product. You are changing settings so that a mistake or a stolen login can do less damage.
Think of your WordPress folder like a shared office. The kitchen (/wp-content/) is open, because that is where the work happens. The cabinet with the master keys (wp-config.php) stays locked. The server room (/wp-includes/ and /wp-admin/includes/) says "staff only", so visitors from the street get turned away.
At the time of writing (23 October 2026), the WordPress Advanced Administration page "Hardening WordPress" was last updated on 14 October 2026. Every rule below comes from that page or from another official source listed at the end.
Why this matters: tight permissions and a disabled file editor will not stop a PHP flaw, but they close a few easy doors that attackers like to try first.
Before you start
- Access to your hosting control panel (cPanel or similar) with File Manager, or SSH access to the server.
- The full path to your WordPress folder. In this guide we use
/home/example/public_htmlas the example. Yours will be different. - A WordPress administrator login, so you can check Site Health afterwards.
- A fresh backup of your files and database, stored somewhere other than the server. If you do not have one, follow our guide to back up your website in cPanel with an offsite copy and a test restore before you continue.
- About 30 minutes, plus 10 more for testing.
- To know your web server. The
.htaccesssteps work on Apache and LiteSpeed. They do nothing on Nginx, which has its own section below.
Risk level: low to medium. Permission changes and .htaccess rules can break a site if you mistype them, which is why every step starts with a copy of what you are about to change.
Quick tip: if you are not sure whether your site runs on Apache, LiteSpeed or Nginx, ask your host. cPanel's own support article says LiteSpeed reads Apache configuration files directly and is compatible with Apache .htaccess rules, so the .htaccess steps apply there too.
The six checks, step by step
Work through these in order. After each step, load your home page and dashboard in a private browser window, so if something breaks you know which change caused it.
Step 1: Take a copy of the files you will change
You may edit .htaccess and wp-config.php. Before either change, save private copies outside every web-served directory and record the originals’ owner, group and mode. A backup in public_html—even a file ending in .bak—may be downloadable if PHP or server routing changes.
For SSH, first confirm that your account home is outside every document root and is not exposed through an alias or symlink. If it is served, choose another private directory with your host. Replace this example path with the actual WordPress root; stop if any command fails.
backup_dir="$(mktemp -d "$HOME/wp-hardening.XXXXXXXX")" &&
chmod 700 "$backup_dir" &&
cp -p /home/example/public_html/wp-config.php "$backup_dir/wp-config.php" &&
chmod 600 "$backup_dir/wp-config.php" &&
cp -p /home/example/public_html/.htaccess "$backup_dir/.htaccess" &&
printf "Private backup: %s\n" "$backup_dir"In cPanel File Manager, enable Show Hidden Files (dotfiles), then download .htaccess and wp-config.php to private local storage. Do not use Copy to put another wp-config.php or .htaccess backup in public_html. If .htaccess is absent, confirm the web server and document root before adding a new file.
What you should see: the two private copies are outside every website directory. Check that the wp-config.php copy is readable only by the owner or otherwise protected by the storage service. Do not place either copy beside the live file.
If you previously made a wp-config.php.bak or similar copy in a web directory, remove it after confirming a private backup exists. If it was publicly retrievable, treat the database credentials and WordPress salts as potentially exposed and ask the host or responder to assess access and rotate secrets.
Step 2: Audit the 755/644 reference values before changing permissions
WordPress describes 755 for directories and 644 for ordinary files as one possible scheme, not a universal command for every installation. Ownership, PHP execution user, special plugin directories and existing exceptions matter. Do not make an entire mixed website tree uniformly 755/644 without mapping those dependencies.
The hardening page recommends this layout:
- All files are owned by your user account and writable by you.
- The WordPress root folder,
/wp-admin/and/wp-includes/are writable only by your account. The exception is.htaccess, if you want WordPress to write rewrite rules for you. /wp-content/is writable by your account and the web server./wp-content/themes/is writable by the web server only if you use the built-in theme editor./wp-content/plugins/is writable only by your account.
First record the existing owner, group and mode of the main locations. Use the following read-only commands only after replacing the example installation path:
stat -c "%a %U:%G %n" /home/example/public_html/wp-admin /home/example/public_html/wp-includes /home/example/public_html/wp-content /home/example/public_html/wp-config.phpTo locate possible exceptions in the two core directories, this read-only command prints directory paths whose mode differs from 755. A difference needs review; it is not automatically a defect.
find /home/example/public_html/wp-admin /home/example/public_html/wp-includes -type d ! -perm 755 -printRun an equivalent scoped check for ordinary core files with your host or developer. Do not run a site-wide recursive chmod: it can change private configuration files, plugin-created storage, other applications and special permission exceptions. Empty output from one check does not prove correct ownership or safe update behavior.
In cPanel File Manager, inspect and change a specific file or folder only after confirming its owner and required access. For a broad correction, ask your host to map the account/PHP user and apply a reviewed, backed-up plan; test uploads and updates afterward.
If PHP runs as a different user, WordPress may need different ownership or permissions for uploads and updates. Use Site Health and a real upload/update test to identify a problem, then ask your host for the least-privilege fix. Do not respond by setting wp-content or the whole site to 777.
Step 3: Lock down wp-config.php
wp-config.php holds the login details WordPress uses to reach your database. It is the most valuable file in your install.
The hardening page says to make sure "only you (and the web server) can read this file (it generally means a 400 or 440 permission)." A 400 means only the owner can read it. A 440 means the owner and the group can read it. Nobody can write to it until you change it back.
Do this only after confirming with your host which owner/group PHP uses and that PHP can read the file. The following is an example for a setup where 440 is appropriate, not a universal target. Record the prior mode so you can restore it if access fails.
chmod 440 /home/example/public_html/wp-config.phpIf the site fails after a restrictive mode change, restore the recorded prior mode through the panel or ask the host to correct ownership and group access. Avoid treating world-readable 644 as a permanent fix for wp-config.php.
When you later edit wp-config.php, temporarily grant only the file owner write access if that owner is your account, make the edit, and restore the reviewed restrictive mode. A different ownership model needs host-specific steps; do not paste chmod 640 blindly.
You may also read online that you should move wp-config.php one folder above your WordPress install. WordPress does support this. The hardening page is honest about it: "Some people assert that moving wp-config.php has minimal security benefits", and it warns that a careless move "may actually introduce serious vulnerabilities." My advice: skip it, and do Step 5 instead.
Step 4: Turn off the dashboard file editor
The hardening page puts it simply: "The WordPress Dashboard by default allows administrators to edit PHP files, such as plugin and theme files." That means PHP code can be changed straight from the browser. That is handy for you. It is even handier for someone who steals an admin password.
Made-up example: Sam runs a small bakery site. An old admin password leaks from another service. The attacker logs in, opens the built-in theme file editor, and adds one line of PHP to functions.php that sends visitors to a spam site. With the editor turned off, that easy path is gone, and the attacker has to find a harder one.
This line in wp-config.php turns the editor off. Place it above the line that says /* That's all, stop editing! Happy blogging. */.
define( 'DISALLOW_FILE_EDIT', true );If WP-CLI is available, it can set the constant after the file owner has temporarily obtained the minimum write access needed for this installation. Record and restore the original mode; do not copy a generic chmod sequence when the file has a different owner or group.
cd /home/example/public_html
wp config set DISALLOW_FILE_EDIT true --rawWhat you should see from WP-CLI: a line starting with Success:, like the example in the official WP-CLI documentation for wp config set.
Be realistic about what this does. The hardening page says it "will not prevent an attacker from uploading malicious files to your site, but might stop some attacks." It is one small door closed, not a wall.
Heads up: the WordPress wp-config.php documentation notes that the functionality of some plugins may be affected, because they check whether the user can edit plugins. If a plugin screen stops working after this change, that is the first thing to check.
What about DISALLOW_FILE_MODS? It goes further and blocks installing and updating plugins and themes from the dashboard, and it disables the editor too. That also stops the dashboard updates you probably rely on, so only use it if you deploy updates another way. Our post on safe WordPress auto-updates with a backup plan explains why updates matter so much.
Step 5: Deny web access to wp-config.php
Nobody outside the server ever needs to request wp-config.php in a browser. This rule makes the web server refuse any such request outright, so the file is never handed to a visitor in any form.
The hardening page says to place this block at the very top of your .htaccess file. It tells Apache or LiteSpeed to deny every request for that one file.
<Files "wp-config.php">
Require all denied
</Files>To edit .htaccess in cPanel, select it in File Manager, click Edit, paste the block on the very first line, and save. Over SSH, use any text editor you are comfortable with.
What you should see: your site loads exactly as before. The test comes in the "How to check it worked" section.
Step 6: Block the include-only folders
Some WordPress files are only meant to be loaded by other WordPress files, never opened directly in a browser. These live in /wp-admin/includes/ and in the top level of /wp-includes/. Blocking direct requests to them removes a little attack surface.
This block from the hardening page returns "403 Forbidden" for direct requests to those include-only files. Place it below the wp-config.php block from Step 5, and above the # BEGIN WordPress line, so WordPress never overwrites it.
# Block the include-only files.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>Heads up for Multisite: the hardening page says this rule set does not work well on WordPress Multisite. The wp-includes PHP rule stops ms-files.php from serving images. You can remove that one line to make it work, at the cost of some protection. If you run a single site, which most people do, this does not affect you.
If you already have other rules at the top of .htaccess, such as an HTTPS redirect from our guide on redirecting HTTP to HTTPS with htaccess, keep them. Just keep everything you add outside the # BEGIN WordPress and # END WordPress lines.
If your site runs on Nginx
Nginx has no .htaccess. The WordPress Nginx documentation puts it plainly: Nginx has no directory-level configuration file like Apache's .htaccess or IIS's web.config. So Steps 5 and 6 do not apply as written. Steps 2, 3 and 4 still apply exactly as above.
That same official page gives a global restrictions example, including one rule worth knowing about right now. This location block inside your site's server {} block denies any .php file inside an uploads or files folder, which is a common place for attackers to drop a script.
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}The page also warns that "A typo in Global restrictions file can create loopholes." Test the config before reloading Nginx, and if you cannot edit Nginx yourself, send the block to your host.
How to check it worked
Test from outside the server with a GET request that discards the response body and prints only the HTTP status. A HEAD-only check may follow a different route and cannot by itself establish what a normal browser GET receives. Use a domain you control and avoid displaying configuration-file contents.
This request should now be refused because of Step 5.
curl -sS -o /dev/null -w "%{http_code}\n" https://example.com/wp-config.phpExpected when the Apache/LiteSpeed deny rule applies: 403. A deliberate 404 or a CDN-generated response requires tracing the delivery path. A 200 does not by itself prove the source was disclosed—PHP may execute it—but it means this deny-rule test did not pass and needs investigation.
This request tests the wp-includes rule from Step 6.
curl -sS -o /dev/null -w "%{http_code}\n" https://example.com/wp-includes/version.phpExpected when the include-only Apache/LiteSpeed rule applies: 403. Investigate any other result against the actual server and route instead of assuming the rule is effective.
This request tests the wp-admin/includes rule.
curl -sS -o /dev/null -w "%{http_code}\n" https://example.com/wp-admin/includes/file.phpExpected when the include-only Apache/LiteSpeed rule applies: 403. Investigate any other result against the actual server and route.
This request checks the site itself still returns a normal page.
curl -sS -o /dev/null -w "%{http_code}\n" https://example.com/Expected: 200, or a 301 redirect to your preferred address, the same as before you started.
For the file editor, log in to WordPress as an administrator and look under the Appearance and Plugins menus. You should no longer find a way to edit theme or plugin PHP files.
Quick tip: check a second way. Open Tools > Site Health in your WordPress dashboard. The Status tab lists critical issues, and the Site Health screen flags an outdated PHP version as a critical item on the Status tab. Then open Tools > Site Health > Info and expand Server to see your PHP version, and Filesystem Permissions to confirm WordPress can still write where it needs to. The WordPress documentation says it should be able to write to the main WordPress directory, wp-content, uploads, plugins and themes.
Read the Filesystem Permissions panel carefully
If any required location is not writable, updates or uploads may fail—even if the read-only audit in Step 2 made no changes. The WordPress documentation advises contacting your host. Compare ownership, the PHP worker identity and a real upload/update result before adjusting a mode; do not infer the cause from Site Health alone.
Troubleshooting
500 Internal Server Error after adding the .htaccess rules
Symptom: every page shows "500 Internal Server Error" right after you saved .htaccess. Likely cause: a typo, a missing closing tag like </Files>, or a server that does not allow these directives in .htaccess. Fix: restore your backup copy over the live file, check the site loads, then add the blocks back one at a time to find the culprit.
Restore the private .htaccess copy made in Step 1. The command below works only in the same shell session where backup_dir still points to that private directory; otherwise substitute the saved full path. Confirm the backup exists before overwriting the live file.
test -f "$backup_dir/.htaccess" && cp -p "$backup_dir/.htaccess" /home/example/public_html/.htaccessRules added but curl still shows 200
Symptom: a direct wp-config.php request still returns 200. Possible causes include Nginx ignoring .htaccess, the wrong document root, a proxy response, or a rule that is not allowed. A 200 may be PHP output rather than raw source, so do not call it proven credential exposure without inspecting safely. Ask the host to trace the response and implement the deny at the actual serving layer.
Images missing on a Multisite network
Symptom: uploaded images return errors on sub-sites after Step 6. Likely cause: the wp-includes PHP rule blocks ms-files.php, as the hardening page warns. Fix: remove the line RewriteRule ^wp-includes/[^/]+\.php$ - [F,L] from your block.
Site stops loading after changing wp-config.php permissions
Symptom: the site stops loading after setting 400 or 440. PHP may not be in the owner or group allowed to read wp-config.php. Restore the recorded prior mode to recover service, then ask your host to set the correct ownership and least-privilege readable mode. Do not leave an unnecessarily world-readable config file as the permanent remedy.
Plugin updates or uploads fail after Step 2
Symptom: plugin/theme updates or media uploads fail. If Step 2 was only an audit, it did not cause the failure. Use Site Health and logs to establish whether owner/group access is actually the problem, then have the host apply a narrow fix for the required writable locations. Never set the whole tree world-writable.
A plugin screen breaks after disabling the editor
Symptom: one plugin's settings page stops working after Step 4. Likely cause: the WordPress wp-config.php documentation warns that plugins which check current_user_can('edit_plugins') may be affected by DISALLOW_FILE_EDIT. Fix: comment out the define line, confirm the plugin works, and tell its author.
Security notes and when to call for help
These checks reduce damage. They do not clean a site that is already hacked. If you see files you did not upload, strange admin users or redirects you did not add, stop hardening and follow WordPress.org's own "FAQ: My site was hacked" page, linked from its October 2026 PHP security post.
Also lock the front door. A stolen admin password beats every file permission in this guide. If you have not turned on two-factor login for your hosting panel yet, our guide to two-factor authentication on cPanel, Plesk and DirectAdmin takes about ten minutes.
The one message worth forwarding
Copy this and send it to your host, developer or whoever looks after your site:
"Hi, after the PHP security release on 21 October 2026 (CVE-2026-109618 and CVE-2026-109619), can you confirm the PHP package serving our site is patched, including any vendor backport? I am reviewing WordPress file hardening. Please confirm the account owner and the PHP worker user/group, an appropriate readable mode for wp-config.php, any special writable locations, and whether the site uses Apache/LiteSpeed or Nginx before I apply web-server rules. I have private backups outside the web root and will verify updates and uploads afterward. Thanks."
Patch PHP first. These six checks can reduce file-level exposure, but they do not guarantee containment or remove an existing compromise.
Reader questions
Do I need to update WordPress because of the October 2026 PHP vulnerabilities?
No. WordPress.org said no WordPress update is required or planned for these issues. You need to update PHP itself, to 8.5.12, 8.4.27, 8.3.36 or 8.2.35 or newer.
What file permissions does WordPress recommend?
The official hardening guide gives 755 for directories and 644 for ordinary files as one possible scheme, not a universal bulk-change instruction. wp-config.php should be readable only by the owner and the web/PHP process where needed; 400 or 440 can work when ownership and group membership fit. Ask the host to verify the real process identity and writable locations before changing modes.
Does DISALLOW_FILE_EDIT stop hackers?
Not on its own. WordPress says it will not prevent an attacker from uploading malicious files, but it might stop some attacks by removing the dashboard code editor.
Should I move wp-config.php above the WordPress folder?
WordPress supports it, but its hardening guide notes the security benefit is debated and a careless move can introduce serious vulnerabilities. Denying web access to the file with .htaccess is a simpler step.
Do the .htaccess rules work on Nginx?
No. Nginx has no .htaccess file, so equivalent rules must go into the Nginx server configuration. The rules do work on Apache and on LiteSpeed, which reads Apache .htaccess rules.
Will the wp-includes rule break WordPress Multisite?
It can. The hardening guide says the wp-includes PHP rule stops ms-files.php from serving images on Multisite, and removing that line fixes it at some cost to security.
How can I see my PHP version from inside WordPress?
Open Tools, then Site Health, then the Info tab, and expand the Server section. Site Health also lists an outdated PHP version as a critical security issue on the Status tab.
Was this guide helpful?
Help us make the next update better.
Sources & further reading
- WordPress Advanced Administration: Hardening WordPress
- WordPress News: Critical PHP security release
- PHP.net 2026 news archive: security advisory
- WordPress Documentation: Site Health screen
- WordPress Advanced Administration: wp-config.php
- WordPress Advanced Administration: Nginx
- WP-CLI: wp config set
- cPanel Docs: File Manager
- cPanel Support: What is LiteSpeed Web Server
- curl man page
What changed
Media repair on 24 October 2026: added an original article-specific cover with accessible alt text; article content and original publication date were preserved.
Originally published . About our editorial updates.



