Viewing and Changing WordPress Default Permissions

Many issues can go wrong if your WordPress default permissions have changed due to some unforeseen circumstance or a migration has gone bad due to some abnormal hosting environment.

The default Linux permissions for most hosts WordPress sites are 644 for files and 755 for folders which is:

 file is rw-r–r–
folder is drwxr-xr-x

For a file this allows the owner to read/write to it whilst everyone else just gets read access only.

For a folder the owner gets full access whilst everyone else get read and execute access but not write, the execute access allowing users to move into the directory.

You can view the permissions via the command line in your WordPress webroot by running…

 ls -la

Giving sample output like so

-rw-r--r--+ 1 wpbeaches wpbeaches 5447 Dec 6 21:29 wp-activate.php
drwxr-xr-x+ 10 wpbeaches wpbeaches 4096 Apr 12 2016 wp-admin
-rw-r--r--+ 1 wpbeaches wpbeaches 364 Apr 12 2016 wp-blog-header.php
-rw-r--r--+ 1 wpbeaches wpbeaches 1627 Dec 6 21:29 wp-comments-post.php
-rw-r--r--+ 1 wpbeaches wpbeaches 2580 Apr 28 19:18 wp-config.php
-rw-r--r--+ 1 wpbeaches wpbeaches 2853 Jan 7 2016 wp-config-sample.php
drwxr-xr-x+ 15 wpbeaches wpbeaches 4096 May 10 14:54 wp-content

 

You can also see the numeric permissions of the files and folders at the beginning of the lines by running…

ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
             *2^(8-i));if(k)printf("%0o ",k);print}'

This will output with the numeric permission prefix like so…

644 -rw-r--r--+ 1 wpbeaches wpbeaches 5447 Dec 6 21:29 wp-activate.php
755 drwxr-xr-x+ 10 wpbeaches wpbeaches 4096 Apr 12 2016 wp-admin
644 -rw-r--r--+ 1 wpbeaches wpbeaches 364 Apr 12 2016 wp-blog-header.php
644 -rw-r--r--+ 1 wpbeaches wpbeaches 1627 Dec 6 21:29 wp-comments-post.php
644 -rw-r--r--+ 1 wpbeaches wpbeaches 2580 Apr 28 19:18 wp-config.php
644 -rw-r--r--+ 1 wpbeaches wpbeaches 2853 Jan 7 2016 wp-config-sample.php
755 drwxr-xr-x+ 15 wpbeaches wpbeaches 4096 May 10 14:50 wp-content

This makes it easy at a quick glance to see what might be wrong.

Changing all files and folders to WordPress Default Permissions

On occasion you may need to recursively change all the files and folders throughout the filing structure, whilst in the webroot you can run…

find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;

Now all your files and folders in subsequent directories will have the new permissions applied, be mindful that this is what you want and do not have other files and folders that are non-WordPress with certain permission settings.

 

Ref & Ref & Ref

Leave a Comment





%d bloggers like this: