Script, CSS & Image permission or 404 issue after installing Magento 2

0
68
views
Script, CSS & Image permission or 404 issue after installing Magento 2
Advertisement

After installing Magento 2, sometimes frontend side as well as admin side js, css, and images can not load properly. This problem occurs because of file permission issue.

Though Magento 2 recommends to set ownership of all files & folders to web server group, sometimes this is not possible due to some reasons. For example on shared hosting, developer can not change ownership of file & folder.

To overcome this problem, we need to set permission 755 to each directory (Magento recommends 700) and we need to set permission 644 to each file (Magento recommends 600).

In /vendor/magento/framework/Filesystem/DriverInterface.php ,

Change the line number 20 from

const WRITEABLE_DIRECTORY_MODE = 0770;

To

const WRITEABLE_DIRECTORY_MODE = 0755;

Also, change the line no 25 from

const WRITEABLE_FILE_MODE = 0660;

To

const WRITEABLE_FILE_MODE = 0644;

After above change, rename pub/static folder with “static_” or any other name just for backup purpose.

After that execute following command from terminal (SSH).

php bin/magento setup:static-content:deploy

After executing above command, new static folder will be created under pub folder with necessary permissions. Now refresh your front page or admin page. It will work fine.

To set permissions 755 & 644 to all directories & files of Magento, please execute below commands via terminal(SSH).

1) This command will set permission to 755 for all the Directories.

find . -type d -exec chmod 755 {} \;

2) This command will set permission to 644 for all the Files.

find . -type f -exec chmod 644 {} \;

I Hope this will help you. and incase if this solution is not working for you and you find another solution for that then I’ll request you all the guy’s please leave your comment below share to all.

Thank you ☺,
Mayank Zalavadia

Previous articleMagento 2 System Requirements
Next articleMagento 2 Speed Up
I am Magento Certified Developer Plus and I enjoy building new code as much as I loves nature.
SHARE