Magento 2 – Fix Missing Write Permissions in Directory pub/static During Setup Upgrade

magento2permissionsstatic-content

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'

Best Answer

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.

Related Topic