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?
7 Answers 7
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
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
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 Chikanizus– zus2018年12月15日 10:54:53 +00:00Commented Dec 15, 2018 at 10:54
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
Run this command :
chmod -R 777 var/ pub/
-
this will be solve your cache validate problem.Ravi Varma– Ravi Varma2018年08月09日 12:47:01 +00:00Commented Aug 9, 2018 at 12:47
-
How can i give write permission to generated folder in windows? @Ravi Varmazus– zus2018年12月15日 10:54:26 +00:00Commented Dec 15, 2018 at 10:54
Run this command For Ubuntu
sudo chmod -R 777 var/* pub/* generated/*
Run this command:
sudo chmod -R 777 var/
-
1don't let friends 777Rizwan Khan– Rizwan Khan2019年07月01日 12:56:25 +00:00Commented Jul 1, 2019 at 12:56