brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Guide: fix your WordPress file permissions without breaking the site

fix your WordPress file permissions without breaking the site

Guide wordpress

6 steps 5 min read

A WordPress install with sloppy file permissions works fine right up to the moment it gets abused, which is why I’d rather spend ten minutes on this than find out the hard way. This is how I’d check what you have, set the values WordPress recommends, and not lock yourself out in the process. Fair warning: the picture below is the thing to avoid.

Time
5 min
Steps
6
Updated
26 Nov 2026

You will learn

  • Back up first
  • Look before you change
  • Set the recommended values
  • Tighten wp-config.php
  • Switch off the dashboard file editor
A FileZilla permissions dialog with 777 typed into the numeric value field

What you get and what you need

At the end, directories are 755, files are 644, wp-config.php is locked down further, and the dashboard theme and plugin editor is switched off. You need SSH access (or a host that lets you run commands), the path to your WordPress folder, and ten minutes. On shared hosting without SSH, the File Manager in cPanel or your SFTP client can set the same numbers per file or folder.

The numbers come from the WordPress hardening guide on developer.wordpress.org. The pitfalls come mostly from Nick Schäferhoff’s article on Torque, which is from 2024 but still matches the official docs.

Step 1 of 6: Back up first

Permission changes can take a site down with a white screen or odd warnings, a risk Schäferhoff calls out too. My advice: make a backup of the files and the database before you touch anything. A plain copy is enough for the files:

cp -a /var/www/example.com /var/www/example.com.bak

Replace the path with your own. For the database, use your host’s backup tool or wp db export if you have WP-CLI.

Step 2 of 6: Look before you change

This only lists things, it changes nothing. It shows directories that are not 755 and files that are not 644:

find /var/www/example.com -type d ! -perm 755 | head
find /var/www/example.com -type f ! -perm 644 | head

If you see 777 anywhere, that is the one I’d worry about. Torque’s article explains why: 777 lets everyone read, write and run the file, including whoever uploaded something nasty. Also check the owner with ls -l. Files should belong to your own user account, not root, and according to the WordPress docs the web server only needs write access to the places WordPress writes to, mainly wp-content.

These are the two commands from the hardening guide. They are recursive, so double check the path first. A typo here changes permissions on the wrong tree, which is why you made that backup.

find /var/www/example.com -type d -exec chmod 755 {} \;
find /var/www/example.com -type f -exec chmod 644 {} \;

Open the site and the dashboard. Upload an image, then update a plugin. If the upload fails, the uploads folder is not writable by the account PHP runs as. That is an ownership problem, so fix the ownership instead of jumping to 777. Ask your host which user PHP runs as, or fix the group ownership.

The chmod manual page open in a terminal

Step 4 of 6: Tighten wp-config.php

This file holds your database password. The hardening guide says it should generally be 400 or 440, readable only by you and the web server. Torque lists 400, 440, 600 and 640 as options, so there is no single right answer; it depends on who PHP runs as on your host.

chmod 440 /var/www/example.com/wp-config.php

If the site shows an error after this, I’d set it back to 640 or 644 and ask the host which value works. On Apache you can also block web access to the file with a <Files "wp-config.php"> rule containing Require all denied at the top of .htaccess, which is also from the official guide.

Step 5 of 6: Switch off the dashboard file editor

Add this line to wp-config.php, above the line that says to stop editing:

define( 'DISALLOW_FILE_EDIT', true );

That removes the theme and plugin editor from the dashboard. The docs are honest about its limits: it does not stop an attacker from uploading files, it just removes an easy tool from a hijacked admin account. I’d still switch it off, because nobody should be editing PHP in a browser textarea anyway.

Step 6 of 6: How to check it worked, and how it breaks

Run the two find commands from step 2 again. Apart from wp-config.php, they should print nothing. Then do a real update in the dashboard, since that is where wrong ownership shows up: WordPress asks for FTP details when it cannot write files itself.

The usual ways it breaks: a plugin that wants to write a cache folder, a host that sets its own ownership, or going too strict. Torque warns that values like 000 cause warnings and white screens. Some hosts also lock files so even admins cannot change them, so open a support ticket instead of running another chmod.

Further reading

Link