1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Understand CHMOD (file rights on server)
CHMOD (abbreviated change mode) allows you to change the access permissions of a file or directory.
Rights (read on Wikipedia) available for each person/group are as follows:
- read: gives the right to list (also requires the right execution) and read in a directory and/or read a file
- Writing: gives the right to create, edit, rename, delete files and/or directories
- execution: for a directory: gives the right to cross it to read its subdirectories -> For a file: gives the right to run it if it is a program or script for example.
- set uid (read on Wikipedia): on a file with execution rights this will have the effect of executing it with the owner's rights if it uses the system call execve or setuid
- set gid (read on Wikipedia): all the new files created will belong to the directory group and on a file with the running rights this will have the effect of executing it with the rights of the group
- ticky bit (read on Wikipedia): on a directory, directory files may be renamed or deleted only by the owner, even if other users have the right to write. Not really useful right on files
The FTP File Manager allows you to change the permissions of the files (including /web).
Most FTP software/clients allow you to change file access rights; the function is usually called "CHMOD" and is under "Properties", "Permissions" or "Attributes" (usually by right clicking on the file or folder to be modified). A box often allows permissions to be applied to all subdirectories and files in the folder in recursive mode.
When you have checked the permissions that interest you, validate and the rights will be changed except those that you do not have permission to change or rather that the user under which you are identified is not entitled to change.
Example with Filezilla:
Read more
When talking about changing permissions, it is usually a matter of making a "chmod 777
", "chmod 666
"or something. So three digits of which:
- the first corresponds to the owner's rights
- the second corresponds to the rights of the group
- the third digit corresponds to the rights of the other users.
And the rights are broken down as follows:
- "4" for the right to read (read)
- "2" for the right of writing (write)
- "1" for the right of enforcement (execution)
Then just add these numbers. P.ex if you want all rights for the owner but no rights for others, you will make "chmod 700" (4 + 2 + 1 = 7). If you only want reading and writing rights for everyone (4 + 2 = 6), you will make a "chmod 666".
These values are known from any good FTP software/client, so you will have the opportunity to put the number directly into your FTP software/client for permissions to be changed.
To change permissions on files or directories in PHP, you can also do so with the "chmod" function as in the following example:
chmod ("/un_dossier/un_fichier", 0755)
Note that the value to be applied must be in octale, hence the required zero front. 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("/un_dossier/un_fichier", octdec($mode))