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

Posted on 25 January, 2016

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 <Your Magento Folder>/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).

<path of your magento directory> 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 {} \;


Dilip Jivani , Managing Director
Magento Technical Notes

Post Your Review

X

Your Review has been posted

5 Comment(s)

Adam H

Posted on 25 May, 2016

I never ever ever have left a comment on anything online. I am a one man show trying to get a site up and running. I was about to give up on Magento 2 and after an hour of looking into countless forums and articles, this was such a simply laid out solution. You are the man!

Nir Goldman

Posted on 17 May, 2016

Thanks for the help! you think there is a better way to do it without override the core?

prateek yadav

Posted on 12 May, 2016

Great :), simple and quick have searched all over but not found such a good answer for this issue. the author is having great knowledge base !!!

cj

Posted on 9 March, 2016

Hi man website work fine now, buth still no css ni img in admin page, please help.

cj

Posted on 9 March, 2016

Thx man i fight long time with this, great post :)