I accidentally run some magento's command as root user and some directories and files have messed up permissions.

Is there any way to reset the permissions because currently I'm getting errors such as:

UnexpectedValueException: The stream or file "/var/www/shop//var/log/system.log" could not be opened: failed to open stream: Permission denied in /var/www/shop/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:108 Stack trace: #0

  • What webserver you using? Do you have a magento2 specific user? What user does the web server run as? Commented Feb 22, 2020 at 2:21
  • Web server runs as user web (unprivileged user), and group www-data. Running on nginx. Commented Feb 22, 2020 at 11:43
  • You need a megento2 user, that needs to be able to write to the magento2 installation directory, this is also who will run the cron jobs. Commented Feb 22, 2020 at 16:37
  • I do ... the user is web. It's also a member of www-data. That is my magento user (web). I could probably name the user more aptly. Commented Feb 22, 2020 at 16:48
  • OK, try what I wrote, Commented Feb 22, 2020 at 17:30

1 Answer 1


Assuming the following premises.

  1. Web server is runing with user:group www-data:web-data.
  2. Web server is running with umask 0002.
  3. Magento2 user:group is web:web.
  4. web user is also a member of www-data group.
  5. Magento2 installation directory is /var/www/shop.

Do these following changes, either as root or prefixed with sudo.

## We're setting a readable baseline, for all directories.  
chown web:www-data -R /var/www/shop
find /var/www/shop -type d -exec chown 2755 {} +

# These directories must be writable by both users. 
find ./var ./generated ./vendor ./pub/static ./pub/media ./app/etc -type d -exec chmod 2775 {} +
find ./var ./generated ./vendor ./pub/static ./pub/media ./app/etc -type f -exec chmod 0664 {} +
  • 1
    I know this has been over a year but I found this answer while googling after I messed up my permissions on the server Commented Aug 20, 2021 at 22:35

Your Answer

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

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