Securing VPS/Servers

WordPress File Permissions on a VPS: Correct Owner and Modes

The correct WordPress file permissions on a VPS: 755 for directories, 644 for files, 640 for wp-config.php, who should own them, and the commands that reset everything.

The correct WordPress file permissions on a VPS are 755 for directories, 644 for files and 640 (or 600) for wp-config.php. The modes are the easy half. Most permission errors come from the other half, ownership: the files belong to a different user than the one PHP runs as, so WordPress cannot write where it needs to.

If you see "Could not create directory", "The update cannot be installed because some files could not be copied. This is usually due to inconsistent file permissions", or WordPress asks for FTP credentials when you install a plugin, find out which user PHP-FPM runs as, give that user ownership of the files it must write, and reset the modes with the two find commands below.

The modes follow the WordPress documentation and the commands are standard Linux tools; they were not run on a test server for this article.

What the errors mean

What you seeLikely causeWhere to look
WordPress asks for FTP credentials ("Connection Information")The WordPress files are owned by a different user than the one PHP runs asOwner of the files compared with the PHP-FPM user
"Could not create directory."PHP cannot write to wp-content, wp-content/plugins, themes or upgradeOwner and mode of those folders
"...some files could not be copied. This is usually due to inconsistent file permissions."Some core files are owned by another user, often root after a manual copy or a WP-CLI run as rootfind for files with the wrong owner
"Unable to create directory wp-content/uploads/2026/11. Is its parent directory writable by the server?"PHP cannot write to uploadsOwner of wp-content/uploads
Everything looks right, still "Permission denied" on AlmaLinux or Rocky LinuxSELinuxLast section

Check which user PHP-FPM runs as

PHP-FPM is the service that runs PHP for nginx. Its worker processes run as the user set in the pool configuration, and that is the user who needs access to the files. nginx's own user only needs to read them.

ps -eo user:20,cmd | grep '[p]hp-fpm: pool'

# Ubuntu, Debian (default: www-data)
grep -E '^(user|group)' /etc/php/8.5/fpm/pool.d/www.conf

# AlmaLinux, Rocky Linux (default: apache)
grep -E '^(user|group)' /etc/php-fpm.d/www.conf

Replace 8.5 with your PHP version (8.3 on Ubuntu 24.04, 8.4 on Debian 13). Then look at who owns the site:

stat -c '%U:%G %a %n' /var/www/example.com /var/www/example.com/wp-config.php /var/www/example.com/wp-content/uploads

To list everything not owned by the expected user:

sudo find /var/www/example.com ! -user www-data | head -20

Who should own the files

There are two workable models. The trade-off is convenience against how much damage a hacked plugin can do.

Model 1: the PHP-FPM user owns everything. Dashboard updates, plugin installs and automatic security updates work without further setup. The cost is that any code running in PHP, including a vulnerable plugin, can rewrite every PHP file of the site. This is the common choice for a single site on its own VPS, and it is acceptable if you keep updates automatic.

# Ubuntu, Debian
sudo chown -R www-data:www-data /var/www/example.com

# AlmaLinux, Rocky Linux
sudo chown -R apache:apache /var/www/example.com

Model 2: a separate deploy user owns the code. A normal login user (here deploy) owns the files, the PHP-FPM group may read them, and PHP can write only to wp-content/uploads. An attacker who gets code execution through PHP cannot change core, plugin or theme files. The cost is that the dashboard can no longer update or install anything: you update over SSH with WP-CLI run as deploy, and you have to do it promptly yourself.

sudo chown -R deploy:www-data /var/www/example.com
sudo chown -R www-data:www-data /var/www/example.com/wp-content/uploads

Some plugins also write to their own folder below wp-content, for example a cache folder. Give those folders to the PHP-FPM user in the same way, one by one, when a plugin reports that it cannot write.

Reset the modes with find

A mode is three digits: owner, group, everyone else. 7 is read, write and enter, 5 is read and enter, 6 is read and write, 4 is read only. Directories need the "enter" bit, files do not, which is why the two get different modes and why one recursive chmod -R is the wrong tool.

cd /var/www/example.com
sudo find . -type d -exec chmod 755 {} +
sudo find . -type f -exec chmod 644 {} +
sudo chmod 640 wp-config.php

wp-config.php holds the database password, so other users on the server should not be able to read it. With model 1 you can go to 600, because the owner is the only user that needs it. With model 2 keep 640 and the group set to the PHP-FPM group, otherwise PHP cannot read the file and the site stops with a database or configuration error.

Verify the result:

stat -c '%U:%G %a %n' . wp-config.php wp-content wp-content/uploads
sudo find . -type d ! -perm 755 | head
sudo find . -type f ! -perm 644 ! -name wp-config.php | head

# can PHP read the config and write to uploads?
sudo -u www-data test -r wp-config.php && echo "config readable"
sudo -u www-data test -w wp-content/uploads && echo "uploads writable"

The two find checks should print nothing. If a file is readable by mode but PHP still cannot reach it, a parent directory is blocking the way. namei -l /var/www/example.com/wp-config.php prints the owner and mode of every folder on the path.

Why 777 is never the fix

Mode 777 lets every user and every process on the server create, change and delete files in that directory. Any other compromised service or account on the server can then plant a PHP file in the site.

The WordPress file permissions documentation says the same: no directory should be given 777, not even the uploads directory. When 755 does not work, the owner is wrong. Fix the owner. To find leftovers from earlier attempts:

sudo find /var/www/example.com -perm -o+w ! -type l

This lists everything that is writable by "everyone else". The output should be empty. If you did not set those modes yourself, treat it as a possible compromise and read cleaning up a hacked WordPress site.

The FTP credentials prompt and FS_METHOD

Before WordPress installs or updates anything, it writes a temporary file and compares that file's owner with the owner of its own PHP files. If the two match, it writes directly to disk. If they differ, it assumes direct writes would leave files with the wrong owner and asks for FTP or SSH credentials instead.

With model 1, correct the ownership as shown above and the prompt disappears. If the owners differ on purpose but PHP has write access through its group, you can tell WordPress to write directly by adding this line to wp-config.php, above the "stop editing" comment:

define( 'FS_METHOD', 'direct' );

FS_METHOD only chooses the method. It grants no access: if PHP cannot write to the folder, the prompt is replaced by "Could not create directory". With model 2 the prompt is expected, and you update with WP-CLI.

SELinux on AlmaLinux and Rocky Linux

SELinux is a second permission layer that is enabled by default on these systems. It labels every file with a context, and PHP-FPM may write only to files whose context allows it, whatever the owner and mode say. Files under /var/www get the read-only type httpd_sys_content_t by default.

getenforce
ls -Zd /var/www/example.com/wp-content/uploads
sudo ausearch -m AVC -ts recent

Enforcing means SELinux is active, and ausearch shows recent denials. To allow writes, assign the read-write type httpd_sys_rw_content_t to the folders PHP must write to and apply it with restorecon:

# semanage is in the package policycoreutils-python-utils
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/example.com/wp-content(/.*)?"
sudo restorecon -Rv /var/www/example.com
ls -Zd /var/www/example.com/wp-content

For dashboard updates of core files (model 1), use the path "/var/www/example.com(/.*)?" instead. restorecon also repairs the labels of files that were moved in from another location such as /root or /tmp, a frequent cause of "Permission denied" after a migration. WordPress also needs outgoing connections to download updates; if they fail, run sudo setsebool -P httpd_can_network_connect 1.

Do not switch SELinux off to make an error disappear. It limits what a compromised PHP process can reach, which is the same goal as the ownership rules above. For the wider picture, see WordPress security with nginx and the VPS hardening checklist.

Share story:

Continue reading other guides on How VPS.