
In this blog, we will understand about files and folder permissions in Magento 2.
In Magento, file and folder permissions can be set using either the command line (terminal) or a file manager application provided by your hosting provider.
Let’s see all topics related to file and folder permission in Magento 2 one by one as below.
Default Magento 2 File and Folder Permissions
In Magento when we create a file or folder, magento will automatically provide them default permissions.
These default permissions can increase security risks for your important files and folders containing your private or important data.
For example,a text file or folder has 777 permissions, which means everyone gets read, write and execute permissions.
So, anyone can change or fetch your data from that file or folder.
To see the file and folder permissions, we have to run the ls -li command in the command line interface (terminal) to see the permissions of all the files and folders available in that directory.

As you can see in the above image,the permission of all the folders and files inside the one directory.
By running this command we get all the information about file and folder like permission flags, owner name, group name, size of file or folder, last modification date and time etc.
In the above image, the 2nd column is the Permission Flag Column. For e.g. drwxrwxrwx this flag is giving all Permission information about a particular directory.
Position | Description |
1 | Here,"d" if flag of directory, "-" if flag of normal file |
2,3,4 | read(r), write(w), execute(x) permission for user (owner) of file |
5,6,7 | read(r), write(w), execute(x) permission for group |
8,9,10 | read(r), write(w), execute(x) permission for other (world) |
There are two types of commands are available to set or change permissions of files and folders in Magento 2:
- 1. umask Commands
- 2. chmod Commands
We will understand about this commands one by one as below:
Setting Magento 2 Permissions with umask and chmod
1. Modifying Permissions with umask
When a file is created in the system, the permission flags are set according to the file mode creation mask, which can be set using the umask command.
The Umask is a three-digit octal value whose nine bits relate to fields 2-10 of the permission flags.
Some usually used umask values are as below:
umask Values | File Permissions | Folder Permissions |
002 | -rw-rw-r-- | drwxrwxr-x |
007 | -rw-rw---- | drwxrwx--- |
002 | -rw-r--r-- | drwxr-xr-x |
027 | -rw-r----- | drwxr-x--- |
077 | -rw------- | drwx------ |
2. Modifying Permissions with chmod
The chmod (chmod means change mode) command is used to change the permission flags on existing files.
It can be applied recursively using the -R option.
It can be invoked with either an octal value representing the permission flags, or with symbolic representations of the flags.
All chmod commands are as below:
Octal Digit | Binary Representation (rwx) | Permissions |
0 | 000 | none |
1 | 001 | execute only(x) |
2 | 010 | write only(w) |
3 | 011 | write and execute(w+x) |
4 | 100 | read only(r) |
5 | 101 | read and execute(r+x) |
6 | 110 | read and write(r+w) |
7 | 111 | read, write, and execute (r+w+x) |
Setting Magento 2 File Permissions via CLI
In Magento, all files should have 660 permissions.
Such a permission means that the owner and the group can read and write, but other users have no permissions.
In some cases, 660 cannot be used. Then, you should use 644 instead.
Run the below command to apply new permission for files:
find . -type f -exec chmod 644 {} \;
Let our certified Magento team handle all security updates and maintenance to safeguard your website from cyberattacks.
Setting Magento 2 Folder Permissions via CLI
In Magento, all directories should have 770 permissions.
This permission gives read, write and execute permission to the owner and to his group, but no permissions to anyone else.
In some cases, 770 cannot be used. Then, you should use 755 instead.
Run the below command to apply new permissions for folders:
find . -type d -exec chmod 755 {} \;
Configuring pub/static and Media Folder Permissions
In Magento all temporary and media directories (/var, /pub/media, /pub/static) and files should have public access (777 permission).
- find ./var -type d -exec chmod 777 {} \;
- find ./pub/static -type d -exec chmod 777 {} \;
- find ./pub/media -type d -exec chmod 777 {} \;
Troubleshooting Magento Permission Errors
Fixing ‘bash: bin/magento: Permission denied’ Error
Usually, we get this error when we are running some script/file that does not have execute permissions.
All we need to do is to change file permissions and add an executive one for that particular file.
To fix the bash permission denied error, follow below steps:
- Open terminal (shell)
- Navigate to the folder with the script
- Run below command to change file permission settings:
- chmod +x path_to_file/file_name
Magento 2 file permission Check failed
When permissions are not set properly, the Web Setup Wizard displays this error.
It usually happens when directories in the Magento file system are not writable by the web server user, and the Magento file system owner should also have all permissions.
To solve this error, first you have to keep up with the following prerequisites:
- Check magento is installed at /var/www/html/ this path.
- You should have command line access.
If you have satisfied above conditions, then follow below steps:
- Open terminal (shell)
- Navigate to root directory of your magento by below command
- cd /var/www/html/magento
- Then change permission with below command
- sudo chmod 777 -R var/ generated/ pub/
Misconfigured permissions expose your store to downtime, data breaches, and lost revenue.
Contact us now for a consultation and get your Magento site protected today!
Resetting File and Folder Permissions to Magento Defaults
To reset permissions for Magento 2 you have to run below commands in terminal after navigate to your Magento root directory:
cd <your Magento install dir> find . -type f -exec chmod 644 {} \; find . -type d -exec chmod 755 {} \; chmod 644 ./app/etc/*.xml chown -R :<web server group> chmod u+x bin/magento |
Wrapping Up!
We hope the above blog will help you to understand Magento 2 folder and file permissions.
If anything remains unclear or you’d like tailored, expert guidance, our Magento development specialists are standing by—simply reach out and we’ll handle the heavy lifting for you.