1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Changing access rights and managing permissions for a file or a directory
CHMOD (abbreviation for change mode) allows access permissions for a file or a directory to be changed.
The rights (read at Wikipedia) available for each person/group are as follows:
- read: grants permission to list (also requires the right to execute) and read from a directory and/or read a file
- write: grants permission to create, modify, rename, delete files and/or directories
- execute: for a directory: grants permission to traverse the directory in order to read its sub-directories -> For a file: grants permission to execute it if it is a program or a script, for example.
- set uid (read at Wikipedia): on a file with execution rights, this will have the effect of executing it with the owner's rights if the execve or setuid system command is used
- set gid (read at Wikipedia): all new files created will belong to the directory group and on a file with execution rights this will have the effect of executing it with group rights
- sticky bit (read at Wikipedia): on a directory, the directory's files can be renamed or deleted only by the owner, even if other users are granted writing rights. Not very useful on these files.
We recommend that you use our FTP File Manager which enables you to change file permissions (including those of /web).
Most FTP software allows you to change access rights to files; the function is usually called "CHMOD" and is found in "Properties", "Permissions" or "Attributes" (usually with a right click on the file or folder you wish to change). Often you can tick an option that allows you to apply permissions recursively to all files and subdirectories in the folder.
Once you have ticked the required permissions, OK them and all rights will be modified except those which you do not have permission to change or rather which the user you are logged in as does not have permission to change.Example with Filezilla:
To find out more
When talking about changing permissions, you might generally be asked to do a "chmod 777", "chmod 666" etc. This means you actually need to view these as three separate figures, where:
- the first corresponds to the owner's rights
- the second corresponds to group's rights
- the third number corresponds to other users' rights.
And rights are made up as follows:
- "4" for read permission
- "2" for write permission
- "1" for execute permission
Then simply add the numbers together. For example, if you want to grant all rights to the owner but no rights to the others, execute a "chmod 700" (4 + 2 + 1 = 7). If you wish to grant permissions for all users to read and write only (4 + 2 = 6), execute a "chmod 666".
These values are recognised by any good FTP software, so you have the option of entering the number directly into your FTP client to change permissions.
To modify permissions on PHP files or directories, you can also do so using the "chmod" function as in the following example:
chmod ("/a_folder/a_file", 0755)Note that the value to use must be in octal, which is why the zero in front is compulsory. Be careful when storing the value in a variable, as you will run into an issue with data types. To get round this issue, you can use the octdec() function, as in the following example:
$mode = 0755;chmod("/a_folder/a_file", octdec($mode))