Most compromised WordPress installs we triage do not get owned through a missing patch. They get owned because the web server user can write to wp-content/themes/ and a malicious plugin upload puts a PHP backdoor where Apache will execute it. Locking down filesystem permissions is the cheapest, longest-lived hardening you can apply.
What’s happening
On a default cPanel/CloudLinux setup the WordPress files are owned by the cPanel user, and PHP runs as that same user through CageFS. That is already much better than the old shared-host model where everything ran as nobody. What it doesn’t give you is a separation between code (immutable to PHP) and writable runtime paths (uploads, cache). Without that separation, any code execution bug in any plugin can drop a PHP file into the document root and call it from a browser.
How to verify
Run an inventory of what the PHP process can actually write to. As the site’s cPanel user:
cd ~/public_html
find . -type f -perm -200 -name '*.php' \
! -path './wp-content/uploads/*' \
! -path './wp-content/cache/*' \
| head -50
Anything returned is a PHP file the runtime can overwrite. On a hardened install, the only writable PHP files should be the ones inside wp-content/uploads/ (and even there, PHP execution should be blocked by webserver config) — not core, not wp-config.php, not the theme.
Also check ownership consistency:
stat -c '%U %G %a %n' wp-config.php .htaccess wp-content wp-content/uploads
A drift between expected owner and actual owner is usually how a previous incident left fingerprints.
The fix
The model we run in production:
- Code (
wp-admin/,wp-includes/,wp-content/themes/,wp-content/plugins/): directories0755, files0644, owned by the cPanel user. PHP cannot rewrite them at runtime — deploys go through SSH + Git, not the WordPress UI. - Runtime writable (
wp-content/uploads/,wp-content/cache/,wp-content/upgrade/): directories0755, files0644, owned by the cPanel user. PHP execution disabled at the webserver level via<FilesMatch>/ LiteSpeed equivalent. - Secrets (
wp-config.php):0400, owned by the cPanel user. Readable by PHP, invisible to anyone else. - Top-level (
.htaccess,index.php):0644, owned by the cPanel user.
Apply it once with find . -type d -exec chmod 0755 {} \; and find . -type f -exec chmod 0644 {} \;, then tighten wp-config.php to 0400. Schedule a weekly audit job that diffs current permissions against the expected baseline and pages on drift — the drift, not the initial state, is where real incidents live.
That weekly drift check is a small thing that nobody remembers to look at. It’s one of the things we wire into Monitoring & Support so it just happens.
Stack Harbor operates production WordPress at scale — see Enterprise WordPress for the managed model, or book a WordPress consult for a written read of your current shape.