I'm just starting the experience of Magento 2.1.2 but I'm having trouble : I can't acces to Magento directory due of an error 500. I've put the directory in chmod 775 but my NGINX log say :

2016/10/16 12:56:18 [error] 31168#31168: *512 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Magento\Framework\Exception\FileSystemException: The file "/var/www/magento/var/.regenerate" cannot be deleted Warning!unlink(/var/www/magento/var/.regenerate): Permission denied in /var/www/magento/vendor/magento/framework/Filesystem/Driver/File.php:382

So it's seems to be a permission issue. Anyone get an idea?

2 Answers 2


As you already noted, this is a permissions problem. Try the recommended approach to setting permissions, maybe you made some kind of mistake which excluded some files from receiving the appropriate write permissions.

First navigate to your Magento directory on your server:

cd /var/www/magento

Afterwards, try setting the permissions via this command:

find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; && find var vendor pub/static pub/media app/etc -type d -exec chmod g+w {} \; && chmod u+x bin/magento

If that does not work, go use cd /var/www/magento/var/ and type ls -al to see if the permissions on all files are properly set so that your web server can write / delete all files.

  • Also check ownership, which should be nginx:<magento file system owner> Oct 17, 2016 at 14:58

Try this:

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
php bin/magento indexer:reindex
php bin/magento cache:flush
chmod -R 777 pub var app/etc
  • this worked for me: chmod -R 777 pub var app/etc.....BUT.....is that safe for a production enivonment??
    – styzzz
    Jul 28, 2017 at 3:34

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