1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Understanding CHMOD (file permissions on server)
This guide details CHMOD (short for change mode), which allows you to change the access permissions of a file or directory.
Modify FTP permissions
Permissions (see this Wikipedia guide) available for each person/group are as follows:
- read: allows listing (also requires execute permission) and reading in a directory and/or reading a file
- write: allows creating, modifying, renaming, and deleting files and/or directories
- execute: for a directory: allows traversing to read its subdirectories -> For a file: allows execution if it is a program or script, for example.
- set uid (?): on a file with execute permissions, this will cause it to be executed with the owner's permissions if it uses the system call execve or setuid
- set gid (?): all new files created will belong to the group of the directory, and on a file with execute permissions, this will cause it to be executed with the group's permissions
- sticky bit (?): on a directory, files in the directory can only be renamed or deleted by the owner, even if other users have write permission. This permission is not really useful on files
The FTP Manager file manager allows you to change file permissions (including that of /web).
Most software/FTP clients allow you to change file access permissions; the function is usually called "CHMOD" and is found under "Properties", "Permissions", or "Attributes" (usually by right-clicking on the file or folder to be modified). A checkbox often allows you to apply permissions to all subdirectories and files in the folder, recursively.
Once you have checked the permissions you are interested in, validate, and the permissions will be modified except for those you do not have permission to modify or rather that the user under which you are identified does not have the right to modify.
Example with Filezilla:
Learn more
When talking about changing permissions, it is generally about doing a "chmod 777", "chmod 666" or similar. So three digits where:
- the first corresponds to the owner's permissions
- the second corresponds to the group's permissions
- the third digit corresponds to the permissions of other users.
And the permissions break down as follows:
- "4" for read permission (read)
- "2" for write permission (write)
- "1" for the execute permission
Then, you just need to add these numbers. For example, if you want all permissions for the owner but no permissions for others, you will do "chmod 700" (4 + 2 + 1 = 7). If you want only read and write permissions for everyone (4 + 2 = 6), you will do a "chmod 666".
These values are known to any good FTP software/client, so you will have the possibility to directly enter the number in your FTP software/client to change the permissions.
To change permissions on files or directories in PHP, you can also do it with the function βchmodβ, as in the following example:
chmod ("/a_folder/a_file", 0755)Note that the value to be applied must be in octal, hence the mandatory leading zero. Be careful if you store the value in a variable, you will have a data type problem, which you can bypass with the function octdec(), as in the following example:
$mode = 0755;chmod("a_folder/a_file", octdec($mode))