How to fix error 403 in Magento 2?
When working with Magento 2, you may get 403 forbidden error with the message:
“You don’t have permission to access .htaccess on this server”
This issue illustrates that permission settings of your server are incorrect. Let’s see how to fix it.
→ Struggling with server configurations? Let our specialists help you out! Check out our server configuration service.
Default server permissions used for Magento 2 files and folders are the following:
- 775 for directories. It gives full control for the user and the group.
- 664 for files. It gives the write permission for the user and the group and read-only for everyone else.
Magento 2 recommends using 755 permission for directories and 644 permission for files. These settings mean the following:
- 755 gives full control for the user, but limits control for everyone else, allowing them only traverse directories.
- 644 gives read-write permissions for the user and read-only for everyone else.
These settings provide you with the necessary security level.
→ Learn more about permissions & ownership
To check current Magento permissions assigned to a file or folder, do the following:
- go to the folder containing the needed directory and use the /s- / command;
- then you can see a table where all the files and folders will have a letter: r (read); w (write), or x (execute);
- for the files that don’t have specific permission, you will see a dash instead of the symbols.
If your permissions are not set properly, you’ll see a message in the file manager.
→ Protect your confidential business data by setting up permissions for different admins roles with the Advanced Permissions mode.
To avoid 403 forbidden nginx error in Magento 2, you can set the needed option in your root folder by using these commands:
cd <your Magento install dir>
find . -type f -exec chmod 644 {} \; // 644 permission for files
find . -type d -exec chmod 755 {} \; // 755 permission for directory
chown -R :<web server group> .
chmod u+x bin/magento
Or you can do it automatically with the help of Magento Cleanup utility.
For more information on this topic, check the official guideline.
Login and Registration Form