The 403 error with the message “You don’t have permission to access/on this server” is listed among the most common issues a user can have when using Magento.
Why 403 Error Occurs In Magento 2
In case you have seen this message, its purpose is to indicate that the permission settings of your server are incorrect. The wrong settings related to ownership, groups and permissions lead to the situation where you can’t access the requested file.
How To Fix “You Don’t Have Permission To Access/On This Server”
In order to debug this error, you can use a command to grant permission.
There are 2 default commands used for this purpose, but they’re are for different objects:
- 775: for directories. It allows full permission for the admin and the group.
- 664: for files. User and the group will have the write permission and read-only for everyone.
Yet, for security reasons, Magento 2 recommends using 755, instead of 775 for directories, and 644 for files, instead of 664.
- 755: full control for the user. Everyone else only can traverse directories.
- 644: read-write permission for the user, and read-only for others.
To check the permission for a directory/ file, do the following:
- Go to the folder containing the needed directory and use the /s- / command
- You’ll see a table where all the files and folders will have a letter: r (read); w (write), or x (execute). If the file doesn’t have assigned specific permission, it’ll show a dash “/” instead of letters.
So, to avoid the 403 error, you can:
Step 1: Go to the Magento folder containing the needed directory
Step 2: Run the following command
sudo chown -R $USER:$USER /var/www/magento sudo chmod -R 755 /var/www
Afterwards, you should be able to check the requested directory or file.
Did you find this Magento tutorial useful? If you want to access more similar ones like How To Fix Magento “The Requested URL Was Not Found On This Server” Error, How To Handle “The Promotional Code You Entered Is Not Valid” Error, etc, then subscribe to our blog!