How to fix error 403 in Magento 2?

Magento 2 may cause 403 forbidden errors with the following message:

“You don’t have permission to access .htaccess on this server”

This issue often occurs when there are some incorrect permission settings in your server. Let's figure out how to fix 403 forbidden error in Magento 2?

Do you need help configuring the server? Get in touch with our dedicated Magento 2 developers to help with it.

By the default Magento 2, the following server permissions are used for Magento 2 files and folders:

  • 775 for directories. A user or a group has full control over it.
  • 664 for files. For the user and group, it gives write permission, and for everyone else, it gives read-only permission.

According to Magento 2, directories should have 755 permissions and files should have 644 permissions. Based on these settings, you can apply to:

  • Users have full control over 755, but everyone else has limited control, allowing them to only browse directories.
  • 644 gives read-write access to use and read-only access to everyone else.

A robust security level can also be achieved with these settings.

Follow the steps below to see what Magento permissions are currently assigned to a specific file or folder:

  • Use the /s- / command to navigate to the folder containing the directory that you need;
  • In the table below, you will see each file and folder listed with a letter: r (read); w (write); and x (execute);
  • There will be a dash instead of symbols for the files which do not have specific permissions.

A message will appear in the file manager if your permissions are incorrect.

You can set the needed option in your root folder to resolve the 403 forbidden nginx error in Magento 2 by using the following commands:

cd <your Magento install dir>
find . -type f -exec chmod 644 {} \; // 644 for file Permissions
find . -type d -exec chmod 755 {} \; // 755 for directory permission
chown -R :<web server group> .
chmod u+x bin/magento

Alternatively, you can use Magento Cleanup to perform this task automatically.

For more information on this, read the official guidelines.

If you have any questions or face any kind of issues, please contact us. Our technical experts would be glad to help you.

Categories: General Questions