To Start with the General Drupal Practices, Drupal has suggested standard guidelines on what permissions should be set in order for the system to work and to be secure at the same time :
- Most files should be 644 i.e, -rw-r--r--
chmod 644 filename
- All directories should be 755 i.e, drwxr-xr-x
chmod -R 755 directory-name
- Files that are intended to be executed using command line should have the executable permission set as 755 i.e, -rwxr-xr-x
chmod 755 filename
How To Check Permissions
Now, the next question here arises how to check the current set permissions of a file or directory :
To check the permission type the command as :
ls -al
How to Set Files Directory Permissions
Now, once you have these permissions correctly, set the next question that comes is, what should be the permission for sites/default and sites/default/files directories where all the assets are stored :
- sites/default/files : 775 i.,e drwxrwxr-x [for all the directories]
chmod g+ws files
- sites/default/files/file.png : 664 i.e, -rw-r–r– [for all files inside of files directory]
chmod 664 filename
Fixing the Permission of Pre-existing Files Directory & Files
- Navigate to sites/default/files directory
- Execute the command to fix all directory permissions
find . -type d -exec chmod g+ws {} \;
- Execute the command to fix all files permissions
find . -type f -exec chmod 664 {} \;
Published on