Question

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'

Was it helpful?

Solution

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.

OTHER TIPS

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 {} \;).

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.

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

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.

Fix bin/magento permission denied

chmod u+x bin/magento

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.

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

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.

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.

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

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" 

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 

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top