Magento – Magento 2 permission issue for cache folder

cachefile-permissionsmagento2

Everytime I install a new module on my Magento 2, I got an error that the cache cannot be created because of the permission. All what I need to do is to run the following command to fix it.

   chmod -R 777 var/

What should I do to fix this permission issue without running the command chmod everytime when a new module is installed?

Best Answer

First Set proper permission to your setup as per magento2 permission guidelines.

You need to add your current group to apache user.

For Ubuntu:

sudo usermod -a -G www-data $USER

For CentOs:

sudo usermod -a -G apache $USER

If you have any issue after this, then you can simply grant ownership of any inaccessible files or folders by below command.

For the entire folder.

sudo chown -R www-data:www-data /var/www/html/your-project/var

For single file.

sudo chown www-data:www-data /var/www/html/your-project/var/somefile.php
Related Topic