2

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?

1

From Magento DevDocs:

The sections that follow discuss requirements for one or two Magento file system owners. That means:

One user: Typically necessary on shared hosting providers, which allow you to access only one user on the server This user can log in, transfer files using FTP, and this user also runs the web server.

find app/code var/view_preprocessed vendor pub/static app/etc generated/code generated/metadata \( -type f -or -type d \) -exec chmod u-w {} + && chmod o-rwx app/etc/env.php && chmod u+x bin/magento

Two users: We recommend two users if you run your own Magento server: one to transfer files and run command-line utilities, and a separate user for the web server software. When possible, this is preferable because it’s more secure.

find var generated pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated pub/static pub/media app/etc -type d -exec chmod g+ws {} +

Check this DevDocs page for more info:
https://devdocs.magento.com/guides/v2.3/config-guide/prod/prod_file-sys-perms.html

1

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
0

Check below command for set permission.

find var vendor pub/static pub/media app/etc -type f -exec chmod u+w {} \; && find var vendor pub/static pub/media app/etc -type d -exec chmod u+w {} \; && chmod u+x bin/magento
  • How can i give write permission to generated folder in windows? @Suresh Chikani – zus Dec 15 '18 at 10:54
0

Change the user for Magento directory and then set permission for all folders

sudo chown -R "$USER":www-data /webdirectory

cd <your Magento install dir> 

find . -type f -exec chmod 644 {} \;                        // 644 permission for files

 find . -type d -exec chmod 755 {} \;                        // 755 permission for directory 

find ./var -type d -exec chmod 777 {} \;                // 777 permission for var folder    

find ./pub/media -type d -exec chmod 777 {} \;

find ./pub/static -type d -exec chmod 777 {} \;

chmod 777 ./app/etc

chmod 644 ./app/etc/*.xml

chown -R :<web server group> .

chmod u+x bin/magento
0

Run this command :

chmod -R 777 var/ pub/
  • this will be solve your cache validate problem. – Ravi Varma Aug 9 '18 at 12:47
  • How can i give write permission to generated folder in windows? @Ravi Varma – zus Dec 15 '18 at 10:54
0

Run this command For Ubuntu

sudo chmod -R 777 var/* pub/* generated/*

-2
Run this command:

sudo chmod -R 777 var/
  • 1
    don't let friends 777 – Rizwan Khan Jul 1 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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