2

I use Docker for my project. After installing the 2.2.6 package with sample data, it gives me problems like the following when I execute php bin/magento cache:clean

The file "/var/www/html/src/generated/code/Magento/Backend/App/Request/PathInfoProcessor/Proxy.php" cannot be deleted Warning!unlink(/var/www/html/src/generated/code/Magento/Backend/App/Request/PathInfoProcessor/Proxy.php): No such file or directory

The generated/code folder can not be deleted and I have to restart my computer then it does let me delete the folder

I use php 7.1.22 , percona 5.6.39 and docker Version 18.06.1-ce-win73 (19507)

Manashvi Birla
  • 2,837
  • 3
  • 14
  • 28
Chen Hanhan
  • 1,549
  • 6
  • 15
  • 20

4 Answers4

4

This happens due to insufficient permissions on the project folder and files.Also www-data must be owner of the project if using Apache as web-server. Please execute commands given below:--

  • sudo chown -R www-data:www-data [path to magento directory]
  • navigate to root of your magento project
  • find . -type f -exec chmod 644 {} \;
  • find . -type d -exec chmod 755 {} \;
  • find ./var -type d -exec chmod 777 {} \;
  • 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
  • chmod u+x bin/magento
GoldenNewby
  • 4,382
  • 8
  • 33
  • 44
Andrew Smith
  • 397
  • 2
  • 17
  • Will this work on shared server. I am facing the same problem. But I can't run sudo command on shared server. Do I just run Chown And the user of the file is not www-data:www-data but its the username of SSH login. I am hosted with siteground and they shifted their server from Cpanel to Sitetools after that I am not able to put the site on developer mode when I switch it back to production its remains broken. I have to restore a back up then its working. Now deleted the code folder through filezilla. Will that fix the problem permanently? Frontend & backend r broken 403 error for static files – rawraj Mar 11 '21 at 05:36
3

An important mania for people who offer their help is to think that all systems are the same.

www-data is the user as long as there are conditions, which many will not meet, because they prefer to use nginx + php-fpm instead of the generalist model.

Other times, included in that model is not the user running Appache, nginx or in the end, php, is www-data.

So the most correct answer is not:

  • Change the owner of the entire magento folder to www-data
  • Neither give permissions 777, this is the most common of all the aberrations in the network.

Lo mas correcto sería

  1. Who executes the process you write in the magento directory?
  2. PHP writes as user or globally?
  3. I have consulted the configuration of my php (php, php-fpm, etc.) to verify which user is the one that executes the operations?

Once we have that data then if we can execute

sudo chown -R <user_correct>: <group_correct>

And please, stop paying attention to those who always write chmod -R 777

Or one day they will wake up without their site in a normal way but full of infections that are hardly curable.

abkrim
  • 3,512
  • 7
  • 43
  • 69
1

Installing magento 2 from the command line of the container in Docker solves the problem of writing permissions in Windows for me

You may need to adjust the parameters:

bin/magento setup:install --base-url=http://local.shop.magento2.com \
--db-host=db_magento2 --db-name=magento --db-user=magento --db-password=magento \
--admin-firstname=magento --admin-lastname=magento --admin-email=user@example.com \
--admin-user=admin --admin-password=admin123 --language=en_US \
--currency=USD --timezone=Europe/Madrid --use-rewrites=1
Chen Hanhan
  • 1,549
  • 6
  • 15
  • 20
  • Unfortunately it didn't work for us. We installed Magento 2 from the command line, and we still get errors with the `generated` folder (using Docker for Windows). – Sébastien May 17 '19 at 15:00
  • We must exclude generated/code and generated/meta folder from Docker volum. So the linux permissions will take effect. – Chen Hanhan May 17 '19 at 20:07
0

Just in case anyone stumbles upon this: Add the following to your docker file

RUN echo "root:root" | chpasswd

This will allow you to switch to root and run chown

su root
password:root
chown -R user:group /folder