Setting file permissions

Computer filesystems allow you to define access rights i.e. permissions for different files and directories which you can use to determine which users can do what: read, write, modify, etc. Setting the permissions properly is important in order to make sure applications/users will be able to access the needed files and folders (e.g. WordPress might need access rights in order to be able to write to files in your wp-content directory and thus enable certain functions).

Permission Modes

 

A permission mode is calculated by adding up values for the user, the file group, and for everyone else. The table above is demonstrating an example for 755.

  • Read 4 - allowed to read files
  • Write 2 - allowed to write/modify files
  • eXecute1 - Read/write/delete/modify/directory

 

 The table above is demonstrating an example for 744.

 Example Permission Modes 

ModeStr PermsExplanation
0477 -r--rwxrwx owner has read only (4), other and group has rwx (7)
0677 -rw-rwxrwx owner has rw only(6), other and group has rwx (7)
0444 -r--r--r-- all have read only (4)
0666 -rw-rw-rw- all have rw only (6)
0400 -r-------- owner has read only(4), group and others have no permission(0)
0600 -rw------- owner has rw only, group and others have no permission
0470 -r--rwx--- owner has read only, group has rwx, others have no permission
0407 -r-----rwx owner has read only, other has rwx, group has no permission
0670 -rw-rwx--- owner has rw only, group has rwx, others have no permission
0607 -rw----rwx owner has rw only, group has no permission and others have rwx
 
 
 
Permission Scheme for WordPress

Permissions will be different from host to host, so this guide will only explain the general principles and is applicable to servers running a standard setup.

Typically, all files should be owned by your user (ftp) account on your web server, and should be writable by that account. Any file that needs write access from WordPress should be owned or group-owned by the user account used by the WordPress (which may be different than the server account).

For example, you may have a user account that lets you send files files back and forth to your server via FTP, but your server itself may run using a separate user, in a separate usergroup, such as dhapache or nobody.

If WordPress is running as the FTP account, that account needs to have write access, i.e., be the owner of the files, or belong to a group that has write access. In the latter case, that would mean permissions are set more permissively than default (for example, 775 rather than 755 for folders, and 664 instead of 644).

The file and folder permissions of WordPress should be the same for most users, depending on the type of installation you performed and the umask settings of your system environment at the time of install.

NOTE: If you installed WordPress yourself, you likely do not need to modify file permissions. Unless you are experiencing problems with permission errors, or you want to, you probably should not mess with this.
NOTE: If you installed WordPress yourself, you likely DO need to modify file permissions. Some files and directories should be "hardened" with stricter permissions, specifically, the wp-config.php file. This file is initially created with 644 permissions, and it's a hazard to leave it like that. See Security and Hardening.

Typically, all core WordPress files should be writable only by your user account (or the httpd account, if different). (Sometimes though, multiple ftp accounts are used to manage an install, and if all ftp users are known and trusted, i.e., not a shared host, then assigning group writable may be appropriate. Ask your server admin for more info.) However, if you utilize mod_rewrite Permalinks or other .htaccess features you should make sure that WordPress can also write to your /.htaccess file.

If you want to use the built-in theme editor, all files need to be group writable. Try using it before modifying file permissions, it should work. (This may be true if different users uploaded the WordPress package and the Plugin or Theme. This wouldn't be a problem for Plugin and Themes installed via the admin. When uploading files with different ftp users group writable is needed. On shared hosting, make sure the group is exclusive to users you trust... the apache user shouldn't be in the group and shouldn't own files.)

Some plugins require the /wp-content/ folder be made writeable, but in such cases they will let you know during installation. In some cases, this may require assigning 755 permissions. The same is true for /wp-content/cache/ and maybe /wp-content/uploads/ (if you're using MultiSite you may also need to do this for /wp-content/blogs.dir/)

Additional directories under /wp-content/ should be documented by whatever plugin / theme requires them. Permissions will vary.

/   
|- index.php
|- wp-admin
|   `- wp-admin.css
|- wp-blog-header.php
|- wp-comments-post.php
|- wp-commentsrss2.php
|- wp-config.php
|- wp-content
|   |- cache
|   |- plugins
|   |- themes
|   `- uploads
|- wp-cron.php
|- wp-includes
`- xmlrpc.php
Using an FTP Client

FTP Programs ("clients") allow you to set permissions for files and directories on your remote host. This function is often called chmod, set permissions or check attributes in a program menu.

In a WordPress install, two files that you will probably want to alter are the index page, and the css which controls the layout. Here's how you change index.php - the process is the same for any file.

In the screenshot below, look at the last column - that shows the permissions. 


 
 
 
 Select the 'index.php' and choose Change Attibutes from the Files menu (Total Commander is used fo this example).

 
 
 The dialog window for setting the permissions will be displayed.
 
 
 

Disegard the check boxes. Just delete the 'Numeric value:' and enter the number you need - in this case it's 666. Then click OK. 

Using the Command Line

If you have shell/SSH access to your hosting account, you can use chmod to change file permissions, which is an advanced method meant for experienced users. Before using chmod it is recommendd that you read some tutorials to learn different ways it can be used. This is important because specifying incorrect permissions can disrupt normal site behaviour.

It only takes two steps to make all the files in your wp-content directory writable, but before doing this first try safer alternatives like modifying just the directory.
 
Try each of these commands first and if they dont work then go recursive, which will make even your themes image files writable. Replace DIR with the folder you want to write in
chmod -v 746 DIR
chmod -v 747 DIR
chmod -v 756 DIR
chmod -v 757 DIR
chmod -v 764 DIR
chmod -v 765 DIR
chmod -v 766 DIR
chmod -v 767 DIR

If those fail to allow you to write, try them all again in order, except this time replace -v with -R, which will recursively change each file located in the folder. If after that you still cant write, you may now try 777.


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 15010