Setting up the right chmod is very important especially when you have shared hosting. A good configuration of permissions (CHMOD) of your files and folders helps you to better secure your website.
The chmod (abbreviation of change mode) is a Unix command executable in a Unix-like environment which defines an access right or permission that is assigned to a file or a folder on Unix systems.
The different permissions are:
- no rights: value 0
- execution only: value 1
- write only: value 2
- write and execute: value 3
- read only: value 4
- read and execute: value 5
- read and write: value 6
- all rights (read, write and execute): value 7
They are expressed by 3 digits (for example: 644, 755, ...):
- the first is the permission granted to the owner of the file or folder (ie you).
- the second is the permission granted to the user group (the users in your group).
- the third is permission granted to any other person.
Examples :
- A chmod 755 for a folder gives the owner full permissions, group members and others read and access permissions. It is a chmod typically used for directories.
- A 644 chmod for a file gives the owner edit and read permissions, group members, and others only read permissions. It is a chmod typically used for files.
WE RECOMMEND THE SETTINGS BELOW:
- For all php files: chmod 440.
- For all cgi and perl files: chmod 550.
- For all other html files or those accessible via the web: chmod 444.
- For all folders: chmod 551.
IMPORTANT: It is very important to set a chmod 440 for all your php files especially files that contain sensitive information (usernames or database passwords for example).
If you want to write to a file or folder, just increase the first digit by 2. For example:
- For all editable php files: chmod 640
- For all editable cgi and perl files: chmod 750
- For all other html files or those accessible via the web and which are editable: chmod 644
- For all editable folders: chmod 751
You can set up the chmod using an FTP client like FileZilla. The change can also be made through the cPanel file manager.