How to set correct WordPress file and folder permissions
Incorrect file permissions cause WordPress errors like “Could not create directory” or “Unable to locate WordPress root directory”, while overly permissive settings (like 777) are a serious security risk. The standard WordPress recommendation is 755 for folders and 644 for files, and both can be set in two commands.
Problem: You need to set the right permissions for all WordPress folders (755) and files (644) as quickly as possible.
Set all permissions at once
Go to the WordPress root folder and run:
cd /var/www/html
# All folders: 755
find . -type d -exec chmod 755 {} +
# All files: 644
find . -type f -exec chmod 644 {} +
find … -exec … {} + passes many files to one chmod call, so it runs fast even on a large site.
What the numbers mean
Each digit is the permission for one group of users: the owner, the group, and everyone else. 4 is read, 2 is write, 1 is execute (for folders: entering the folder), and the digit is their sum.
755 = rwxr-xr-x owner: all; group and others: read + enter (folders) 644 = rw-r--r-- owner: read + write; group and others: read (files) 640 = rw-r----- owner: read + write; group: read; others: none 600 = rw------- owner: read + write; nobody else
To see the owner, group and permissions of a file:
stat -c '%U %G %a' wp-config.php
Protect wp-config.php
wp-config.php contains the database password, so it deserves stricter permissions than other files. Which value works depends on how PHP runs on your server:
600if PHP runs as the owner of the files (PHP-FPM with a separate pool per site, suPHP, most shared hosting);640if PHP runs as the web server user (for example www-data) and that user is the file’s group.
If the site shows “Error establishing a database connection” after the change, PHP can’t read the file: use the other value.
Let WordPress write where it needs to
If WordPress needs to write to a folder (uploads, or updates from the dashboard), give the web server user ownership instead of setting 777:
# Find out which user the web server runs as
ps aux | grep -E 'apache|httpd|nginx|php-fpm' | grep -v grep | awk '{print $1}' | sort -u
# Give that user the uploads folder (replace www-data with your web user)
chown -R www-data:www-data wp-content/uploads
NOTE: Never set files or folders to 777 on a production server. It makes them writable by any process on the server, including malicious scripts from other compromised sites on shared hosting. If WordPress still can’t write files with 755 on folders, the problem is ownership, not permissions: fix it with chown.