I've had a look over here but didn't find any details on the best file permissions. I also took a look at some of WordPress's form's questions over here too but anybody that suggests 777 obviously needs a little lesson in security.
In short my question is this. What permissions should I have for the following:
- root folder storing all the WordPress content
- wp-admin
- wp-content
- wp-includes
and then all the files in each of those folders?
For those who have their wordpress root folder under their home folder:
** Ubuntu/apache
CREDIT Granting write permissions to www-data group
You want to call
usermod
on your user. So that would be:** Assuming
www-data
group existsCheck your user is in
www-data
group:groups yourUserName
You should get something like:
** youUserGroupName is usually similar to you user name
Recursively change group ownership of the wp-content folder keeping your user ownership
chown yourUserName:www-data -R youWebSiteFolder/wp-content/*
Change directory to youWebSiteFolder/wp-content/
cd youWebSiteFolder/wp-content
Recursively change group permissions of the folders and sub-folders to enable write permissions:
find . -type d -exec chmod -R 775 {} \;
** mode of `/home/yourUserName/youWebSiteFolder/wp-content/' changed from 0755 (rwxr-xr-x) to 0775 (rwxrwxr-x)
Recursively change group permissions of the files and sub-files to enable write permissions:
find . -type f -exec chmod -R 664 {} \;
The result should look something like:
Equivalent to:
chmod -R ug+rw foldername
Permissions will be like 664 for files or 775 for directories.
P.s. if anyone encounters error
'could not create directory'
when updating a plugin, do:server@user:~/domainame.com$ sudo chown username:www-data -R wp-content
when you are at the root of your domain.
Assuming:
wp-config.php
hasFTP credentials on LocalHost
define('FS_METHOD','direct');
I set permissions to:
In my case I created a specific user for WordPress which is different from the apache default user that prevent access from the web to those files owned by that user.
Then it gives permission to apache user to handle the upload folder and finally set secure enough file and folder permissions.
EDITED
If you're using W3C Total Cache you should do the next also:
Then it'll work!
EDITED
After a while developing WordPress sites I'd recommend different file permissions per environment:
In production, I wouldn't give access to users to modify the filesystem, I'll only allow them to upload resources and give access to some plugins specific folders to do backups, etc. But managing projects under Git and using deploy keys on the server, it isn't good update plugins on staging nor production. I leave here the production file setup:
www-data:www-data = apache or nginx user and group
Staging will share the same production permissions as it should be a clone of it.
Finally, development environment will have access to update plugins, translations, everything...
www-data:www-data = apache or nginx user and group your-user:root-group = your current user and the root group
These permissions will give you access to develop under
themes
andyour-plugin
folder without asking permission. The rest of the content will be owned by the Apache or Nginx user to allow WP to manage the filesystem.Before creating a git repo first run these commands:
I think the below rules are recommended for a default wordpress site:
For folders inside wp-content, set 0755 permissions:
chmod -R 0755 plugins
chmod -R 0755 uploads
chmod -R 0755 upgrade
Let apache user be the owner for the above directories of wp-content:
chown apache uploads
chown apache upgrade
chown apache plugins
Correct permissions for the file is 644 Correct permissions for the folder is 755
To change the permissions , use terminal and following commands.
755 for folders and 644 for files.
Commands:
Where ftp-user is what user you are using to upload the files