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?

asked Apr 4, 2017 at 10:18

7 Answers 7

3

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
answered Apr 22, 2019 at 5:07
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

answered Apr 21, 2019 at 12:07
0
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
answered Apr 4, 2017 at 10:25
1
  • How can i give write permission to generated folder in windows? @Suresh Chikani Commented Dec 15, 2018 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
answered Apr 4, 2017 at 10:25
0

Run this command :

chmod -R 777 var/ pub/
answered Aug 9, 2018 at 12:46
2
  • this will be solve your cache validate problem. Commented Aug 9, 2018 at 12:47
  • How can i give write permission to generated folder in windows? @Ravi Varma Commented Dec 15, 2018 at 10:54
-1

Run this command For Ubuntu

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

answered Jun 12, 2019 at 5:50
-2
Run this command:
sudo chmod -R 777 var/
Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
answered Apr 21, 2019 at 10:30
1
  • 1
    don't let friends 777 Commented Jul 1, 2019 at 12:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.