chmod stands for change mode and it is used for changing the mode of access where as 777 is the ‘Octal Value’ of the file or directory permission. Here we discuss how to set read-write permissions for the web server.
// USING OCTAL VALUE
// chmod [option] mode file
$ chmod -R 754 /path/to/your/directory
$ chmod 777 /path/to/your/file
// USING SYMBOLIC VALUE
// chmod [option] {u,g,o}{+,-,=}{r,w,x} /path/to/file
$ chmod -v u+rw /path/to/file
$ chmod -cR g+w /path/to/directory
The digits 7, 5, and 4 each individually represent the permissions for the user, group, and others. Each digit is a combination of the numbers 4, 2, 1, and 0:
- 4 stands for “read”,
- 2 stands for “write”,
- 1 stands for “execute”, and
- 0 stands for “no permission.”
So 7 is the combination of permissions 4+2+1 (read, write, and execute), 5 is 4+0+1 (read, no write, and execute), and 4 is 4+0+0 (read, no write, and no execute).
Each digit of the permissions number is a sum of 4, 2, 1 and 0:
- 0 (0+0+0) – No permission.
- 1 (0+0+1) – Only execute permission.
- 2 (0+2+0) – Only write permission.
- 3 (0+2+1) – Write and execute permissions.
- 4 (4+0+0) – Only read permission.
- 5 (4+0+1) – Read and execute permission.
- 6 (4+2+0) – Read and write permissions.
- 7 (4+2+1) – Read, write, and execute permission.
In the example below we have ‘Sybmolic Value’ where File, as denoted by the leading “-” within it’s symbolic value -rwxrwxrwx and Directory, as denoted by the leading “d” within it’s symbolic value drwxrwxrwx
$ ls -l
-rw-rw-rw- 1 sudhanshubajaj admin 1370 Oct 30 2019 index.php
drwxrwxrwx 5 sudhanshubajaj admin 160 Oct 30 2019 lib
-rw-rw-rw- 1 sudhanshubajaj admin 5742 Oct 30 2019 nginx.conf.sample
-rw-rw-rw- 1 sudhanshubajaj admin 1416 Oct 30 2019 package.json.sample
drwxrwxrwx 5 sudhanshubajaj admin 160 Oct 30 2019 phpserver
drwxrwxrwx 14 sudhanshubajaj admin 448 Jan 6 11:33 pub
- Owner: rwx=4+2+1=7
- Group: r-x=4+0+1=5
- Others: r-x=0+0+0=0
r stands for read, w stands for write and x stands for execute.
Magento File system permission.
$ cd <magento_root>
$ find var generated vendor pub/static pub/media app/etc -type f -exec chmod u+w {} +
$ find var generated vendor pub/static pub/media app/etc -type d -exec chmod u+w {} +
$ chmod u+x bin/magento
where permission MODE to apply(+), remove (-) or match (=)