21

The day before, I updated a new module and it was working normally. Now, when I run bin/magento setup:upgrade, I receive the below Exception. I tried setting permissions to 777 (or 770) for the pub folder in Magento 2 but it is not working.

  [Exception]
  Missing write permissions to the following directories: 'pub/static'

6
  • did u manage to resolve this problem ? if so pls post the solution. Dec 2, 2015 at 12:40
  • Are you have same issue ?
    – Lino
    Dec 2, 2015 at 13:05
  • yes i am facing the same issue. how did u resolve it ? Dec 2, 2015 at 13:26
  • I comment some line code in core. Are you want do as me?
    – Lino
    Dec 2, 2015 at 13:28
  • 1
    i posted my relsove in post below. I can try with it
    – Lino
    Dec 2, 2015 at 13:35

15 Answers 15

30

TL;DR truncate pub/static folder.


For me, I had an older installation, which probably had some symlinks and old files which no longer exist.

The issue checkInstallationFilePermissions is that it checks the permissions recursively. Files and folders. I had a missing symlink, and that returned false on the check if it's writable.

How to debug:

  1. setup/src/Magento/Setup/Model/FilePermissions.php

  2. Goto line 143 in method checkRecursiveDirectories

  3. Add the lines var_dump($subDirectory);var_dump($subDirectory->isWritable());

  4. Re run bin/magento setup:upgrade

now you'll see what is really wrong, and you can fix it. Personally i remove everything in pub/static, this will be auto generated content so you should not be worried about that.

5
  • 1
    I removed pub/static completely, after I ran setup:upgrade the only folder inside pub/static is __requirejs folder. Css are missing, no styling what so ever.... Man.. do I wish i haven't done that Feb 17, 2016 at 16:13
  • how can I restore everything in pub/static ? Feb 17, 2016 at 16:34
  • 2
    everything was going so well.... :) i really start to despise this framework Feb 17, 2016 at 17:11
  • 3
    If you remove the contents of pub/static just make sure you don't remove pub/static/.htaccess as it is part of the code base and doesn't get recreated: github.com/magento/magento2/tree/2.0/pub/static
    – mttjohnson
    Jun 8, 2016 at 15:24
  • Perfecto! This was it..
    – Arvind07
    Jul 10, 2016 at 10:45
12

I ran into this error in development because of a broken symbolic link.

I had created a file in a module's view/frontend/web directory that in developer mode was deployed to the pub/static directory using a symbolic link that pointed to the module's directory where the original file is stored.

At some point in development I removed the file from my module, but the symbolic link still existed in pub/static pointing to a file that no longer existed. I expect this would also be the case if I had renamed one of the files.

If a site is in production mode and has had bin/magento setup:static-content:deploy run, that actually copies the files to the pub/static directory instead of creating symbolic links.

In order to find this broken symbolic link I ran a command from the shell

find -L . -type l

Removing the broken symbolic link resolved the problem (for example using find -L . -type l -exec rm {} \;).

1
  • This was the answer to my issue as well, thanks mttjohnson! Jul 6, 2016 at 14:15
6

Inside your Magento root directory run the commands below and your issue should be gone:

$ rm -rf pub/static/*
$ php bin/magento setup:static-content:deploy

Worked for me.

3
  • This will delete .htaccess file too. You need .htaccess file. Nov 4, 2019 at 7:50
  • 1
    @AdarshKhatri no it won't. rm -rf pub/static/* doesn't delete dotfiles. Go ahead and try with a test directory. rm -rf pub/static/.* (notice the dot) would delete htaccess.
    – Erik B
    Jul 22, 2020 at 22:45
  • @medina Thank you 🙏🏻 May 15, 2021 at 11:29
2

You should setup the permissions as it is described in the official documentation: http://devdocs.magento.com/guides/v2.0/install-gde/install/file-system-perms.html

6
  • 1
    can you the actual permissions just cause in-case the url changes.
    – rob3000
    Nov 23, 2015 at 8:27
  • I try again but it not working
    – Lino
    Nov 23, 2015 at 8:31
  • Do not forget to do it recursively into subdirectories: pub, pub/static, etc. Nov 23, 2015 at 8:33
  • ownership is as important as permissions; check the above link and also devdocs.magento.com/guides/v2.0/install-gde/prereq/…. You must have two users; a local user and the web server user Nov 23, 2015 at 15:34
  • the whole idea of setting the permissions at application level is wrong so I think people should avoid the documentation at that section. it will be updated in next versions according to their github issues Apr 4, 2016 at 16:59
1

This is my resolved temporary. I comment line 744 and 466 in <magento_dir>/setup/src/Magento/Setup/Model/Installer.php.

This is line code:

$this->checkInstallationFilePermissions();

I need solution don't change core file.

3
  • The problem is likely due to a broken symlink (answered below) under the pub/static directory. Removing the broken symlink should resolve the problem without modifying core files.
    – mttjohnson
    Jan 7, 2016 at 17:24
  • newtips.co/magento/questions/91184/… This will work Mar 1, 2016 at 6:31
  • @EnvisionEcommerce the link doesn't work.
    – MagePsycho
    Jul 5, 2018 at 7:04
1

If someone is having this issue on Windows os. Just execute the command on a Administrator command prompt and it will work like a charm. Hope this helps someone.

1

Fix bin/magento permission denied

chmod u+x bin/magento

0

These folders needs to have the right permissions like described in: http://devdocs.magento.com/guides/v2.0/install-gde/install/file-system-perms.html

When you remove the contents of the pub/static folder and you give the pub/static folder the permission 770, the message will not show up again.

0

I had the same problem where i could not install Magento via the command line. Simply creating the folder pub/static solved the problem.

0

In my case running upgrade command through non-root user or a user with limited permissions was causing the error. Make sure you run the upgrade command with a user with enough permissions.

0

I verified many times write permissions and everything was good.

  1. I commented this row, which throw me an exception.
  2. Then I ran setup:upgrade.
  3. Reverted back the row with exception
  4. Issue didn't reproduce no more
0

Run the following command, for the following three IP addresses:

<Magento-Directory>php bin\magento maintenance:allow-ips 127.0.0.1, 
<Magento-Directory>php bin\magento maintenance:allow-ips "the ip of my localhost given by the NAT-Router" and
<Magento-Directory>php bin\magento maintenance:allow-ips  "the ip of the NAT-Router" 
0

don't use this :

rm -r pub/static

it will remove all files even .htaccess

you can use this will be better :

rm -rf pub/static/frontend
rm -rf pub/static/adminhtml

after that use :

php bin/magento setup:static-content:deploy en_US -f 
0

You must have deleted pub/static (except .htacess) under the impression that it will be created upon next execution but after executing upgrade command you ended with this :)

Don't worry, execute the deploy command using -f to have everything in flow and expected.

I had the same issue but managed my old working source by following the above trick.

-1

just remove pub/static folder from your magento2

rm -r pub/static

then deploy static content of magento2

php bin/magento setup:static-content:deploy

by using this process my same problem solved.

1
  • 5
    You shouldn't remove the entire pub/static directory as it contains a .htaccess file that is important, and the .htaccess file will not get recreated on any static content deploy. You could run rm -r pub/static/* and that should avoid removing the .htaccess file.
    – mttjohnson
    Jan 7, 2016 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.