- Directories 755, files 644, on almost every web server.
- wp-config.php holds your database password: set it to 640.
- Your deploy user owns the files; the web server user is in the group.
- 777 lets every account on the server rewrite your site. It hides problems rather than fixing them.
- On a normal WordPress site, only the uploads folder needs to be writable by the web server.
What permissions should a web server use?
Set directories to 755 and files to 644. Directories need the execute bit so they can be opened; files only need to be read. The web server should never need to write to your code, only to the folders that hold uploads, cache and logs. Anything looser adds risk and gains nothing.
| What | Octal | Looks like | Why |
|---|---|---|---|
| Directories | 755 | drwxr-xr-x | Owner can change contents, everyone else can enter and list |
| Files | 644 | -rw-r--r-- | Owner can edit, the web server can read |
| wp-config.php | 640 | -rw-r----- | Holds database credentials: group only, never readable by all |
| Uploads directory | 775 | drwxrwxr-x | The web server group needs to write here |
| Shell scripts | 750 | -rwxr-x--- | Owner and group can run it; everyone else has no access |
| SSH private key | 600 | -rw------- | Owner only. SSH refuses to use anything looser |
Learn the first two rows. The rest are exceptions, each with a specific reason.
777 is not a fix
chmod 777 means every account on the server can read, edit and run the file, including accounts you do not control on a shared machine. If a plugin only works at 777, the real problem is ownership, and the fix is chown, not chmod.
How do Linux file permissions actually work?
Every file has three sets of permissions: for its owner, its group and everybody else. Each set says who can read, write or execute it. ls -l shows them in the first ten characters.
$ ls -l /var/www/example.com
-rw-r--r-- 1 deploy www-data 405 Jul 29 09:14 index.php
drwxr-xr-x 4 deploy www-data 4096 Jul 29 09:14 wp-content
-rw-r--r--
|[-][-][-]
| | | +-- everyone else: read only
| | +----- group (www-data): read only
| +-------- owner (deploy): read and write
+---------- file type: - is a file, d is a directoryThe number form adds the permissions together: read is 4, write is 2, execute is 1. So 6 is read and write, 7 is all three, and 5 is read and execute. There is one digit for each of the three sets.
| Number | Permissions | Meaning |
|---|---|---|
| 7 | rwx | Read, write, execute |
| 6 | rw- | Read and write |
| 5 | r-x | Read and execute (the normal setting for a directory others must enter) |
| 4 | r-- | Read only |
| 0 | --- | No access |
755 reads as: owner 7, group 5, everyone else 5.
Execute means something different on a directory
On a file, execute means you can run it. On a directory, it means you can open it and reach the files inside. A directory set to 644 cannot be opened at all, which is why removing the execute bit from a folder makes a whole site return errors.
Which user should own my website files?
Not the web server: this is the most common mistake. On Debian and Ubuntu the web server runs as www-data; on AlmaLinux, Rocky and CentOS it runs as apache or nginx. If that account owns your files, any code the web server runs can rewrite your whole site, which is exactly what an attacker with a webshell (a malicious script uploaded to your site) wants.
The safer setup is a separate deploy user that owns the files, with the web server user in the group. The web server can then read everything, and can write only where you have given the group write access.
# Find out which user your web server actually runs as
ps aux | grep -E '[a]pache2|[n]ginx|[p]hp-fpm' | awk '{print $1}' | sort -u
# Own the files as the deploy user, group them to the web server
sudo chown -R deploy:www-data /var/www/example.com
# Add the deploy user to the web server group so both can collaborate
sudo usermod -aG www-data deployGroup changes need a new login
Adding yourself to a group does not affect the shell you are already in. Log out and back in, or run newgrp www-data, or the permission you just granted will seem to do nothing.
What are the correct WordPress file permissions?
WordPress follows the general rule with two exceptions. wp-config.php should be tighter than everything else, because it holds your database password. wp-content/uploads must be writable by the web server, because that is where media is saved.
| Path | Permissions | Owner:group | Notes |
|---|---|---|---|
| All directories | 755 | deploy:www-data | The default for everything |
| All files | 644 | deploy:www-data | The default for everything |
| wp-config.php | 640 | deploy:www-data | Database credentials live here |
| wp-content/uploads | 775 folders, 664 files | deploy:www-data | Media library writes here |
| wp-content/cache | 775 | deploy:www-data | Only if a caching plugin needs it |
| .htaccess | 644 | deploy:www-data | 664 only while you are editing permalinks |
Everything not in this table gets 755 for directories and 644 for files.
Updating plugins and core without write access
If the web server cannot write to wp-content/plugins, WordPress asks for FTP details when you click update. Update with WP-CLI instead, or let your host do it, rather than opening up the whole plugin folder.
How do I reset broken WordPress permissions safely?
Never run chmod -R 755 across a site: it sets the execute bit on every file, images and PHP included. Use find to set directories and files separately. Run these commands in this order and nothing is left half-broken.
cd /var/www/example.com
# 1. Ownership first: deploy user owns, web server group reads
sudo chown -R deploy:www-data .
# 2. Directories to 755
sudo find . -type d -exec chmod 755 {} \;
# 3. Files to 644
sudo find . -type f -exec chmod 644 {} \;
# 4. Lock down the config file
sudo chmod 640 wp-config.php
# 5. Give the web server group write access to uploads only
# (folders 775, files 664: chmod -R 775 would make every image executable)
sudo find wp-content/uploads -type d -exec chmod 775 {} \;
sudo find wp-content/uploads -type f -exec chmod 664 {} \;
sudo chmod g+s wp-content/uploadsg+s in step 5 is the setgid bit: new files created in uploads take the www-data group automatically, so the fix holds.On a large site, find -exec starts one process per file and can take minutes. find . -type f -print0 | xargs -0 chmod 644 does the same job much faster.
On a live site, take a tested backup first: a reset changes every file and there is no undo. Our backup strategy guide covers what a usable backup looks like.
How do I diagnose a permission problem?
Start from the symptom. Three symptoms cover nearly everything, and each points to a different cause.
| Symptom | Usual cause | Check |
|---|---|---|
| 403 Forbidden on every page | A parent directory is missing the execute bit | namei -l /var/www/example.com/index.php |
| Blank page or 500 error | PHP cannot read a required file | Check the PHP error log for "failed to open stream: Permission denied" |
| Media uploads fail | The web server cannot write to wp-content/uploads | sudo -u www-data test -w wp-content/uploads && echo writable |
namei is the tool people forget: it walks every directory in a path and prints the permissions at each level.
# Shows permissions at every level of the path
namei -l /var/www/example.com/wp-content/uploads
# Test as the web server user itself, which is the definitive answer
sudo -u www-data test -r /var/www/example.com/index.php && echo 'can read' || echo 'cannot read'
sudo -u www-data test -w /var/www/example.com/wp-content/uploads && echo 'can write' || echo 'cannot write'If the error log is your next stop, understanding Linux system logs covers where each service writes and how to follow it live.
How do permissions interact with SFTP and deployments?
Most permission drift comes from mixing access methods. You deploy over SSH as deploy, a colleague uploads over SFTP as webmaster, and a plugin writes as www-data: three owners, and files the rest of the team cannot edit.
- Put every person in the same group and set that group on the site's root folder, so anything anyone creates can be edited by the rest of the team.
- Set the setgid bit on the root folder with
chmod g+s, so new files and folders take its group instead of the creator's default. - Set a shared umask of 002 for the deploy accounts. The umask decides the permissions of new files; 002 makes them 664 and new folders 775, instead of 644 and 755.
- Choose one way to deploy and keep to it. Mixing git pull, SFTP and the WordPress plugin installer on one site is what causes the mess.
sudo groupadd webdev
sudo usermod -aG webdev deploy
sudo usermod -aG webdev webmaster
sudo chown -R deploy:webdev /var/www/example.com
sudo find /var/www/example.com -type d -exec chmod 2775 {} \;
sudo find /var/www/example.com -type f -exec chmod 664 {} \;Isolation limits the damage
On G7Cloud each site runs in its own container with its own files, its own PHP and its own database, so no other customer's account shares your server. The rules above still apply inside the container, but a mistake stays within that one site. See how we secure WordPress hosting.
Frequently asked questions
What are the correct WordPress file permissions?
Directories 755, files 644, wp-config.php 640, and wp-content/uploads 775 for folders (664 for files) so the web server group can save media. Your deploy user should own the files, with the web server user (www-data, apache or nginx) as the group. Nothing on a normal WordPress site needs 777.
Is chmod 777 ever acceptable?
No. 777 lets every account on the server, including any process an attacker runs, rewrite the file. When a plugin only works at 777, the web server user is not in the owning group. Fix it with chown and a group-writable 775 folder.
Should www-data own my WordPress files?
No. If the web server user owns the files, any code it runs can rewrite the whole site, which is what a webshell needs. Have a separate deploy user own the files, put www-data in the group, and give group write access only to uploads and cache.
Why do I get 403 Forbidden after fixing file permissions?
Almost always a directory above the file is missing its execute bit, so the web server cannot get through the path to reach it. Run namei -l on the full path: it prints permissions at every level and shows which directory is blocking.
What is the setgid bit and why should I use it?
setgid (chmod g+s, or a leading 2 in the number form) makes new files and folders take the parent folder's group instead of the creator's default group. On a shared site folder it keeps ownership consistent, so permissions do not drift each time someone different uploads a file.
How do I check permissions as the web server user?
Use sudo -u www-data test -r <path> for read and -w for write. It answers directly, taking account of group membership and every parent folder at once.
About G7Cloud Engineering
Articles written by the engineers who build and run G7Cloud: UK managed hosting and the AI Website Builder. We write about what we operate every day: containers, backups, databases, and the small-business websites that run on them.
More about G7Cloud →