I have installed different Magento sites using nginx. I have 5 sites, 4 of them use php7.1 and there's one that uses php7.0.

I have created two different sites-availaible:

enter image description here

And both of them have sites as these one: (the other magento2.1 uses php7.0 and I comment and uncomment because I still haven't discovered how to use both at the same time -> fastcgi_backend gives error if both are working at the same time)

enter image description here

Now the issue comes when, once all Magento files added, installed and nginx properly set up it gives me an permissions error:

2019/03/15 11:20:31 [error] 3266#3266: *19 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught RuntimeException: Can't create directory /var/www/html/parera_dev.com/generated/code/Magento/Directory/Helper/Data/.
Class Magento\Directory\Helper\Data\Proxy generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. in /var/www/html/parera_dev.com/vendor/magento/framework/Code/Generator.php:135
Stack trace:
#0 /var/www/html/parera_dev.com/vendor/magento/framework/Code/Generator/Autoloader.php(35): Magento\Framework\Code\Generator->generateClass('Magento\\Directo...')
#1 [internal function]: Magento\Framework\Code\Generator\Autoloader->load('Magento\\Directo...')
#2 [internal function]: spl_autoload_call('Magento\\Directo...')
#" while reading response header from upstream, client:, server: parera.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.1-fpm.sock:", host: "www.parera.com"

The permissions I set up where these:

sudo find . -type f -exec chmod 664 {} \;
sudo find . -type d -exec chmod 775 {} \;    
sudo find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \;
sudo find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \;
sudo chown -R raul:www-data .;
sudo chmod u+x bin/magento;
sudo systemctl restart nginx.service;

With these permissions, my other 7.1 sites work, well, 1 of 4 work, the other 3 give me this exact error.

Exceptionally I added this command to try and fix it but no luck:

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

I compile and deploy after but no change.

I share the nginx conf because it might be some kind of nginx conf error.

Thank you

  • your php-fpm user must be raul or www-data and dont run commands as root – MagenX Mar 17 '19 at 9:30

Had the same error on local environment.

The error was due to an nginx permissions error.

Running this on macOS with local brew services nginx.

Local dev env

  • macOS
  • brew services nginx, php7.2
  • Magento 2.3.4

Error in the /usr/local/var/log/nginx/error.log file was

 [crit] 7566#0: *31067 open() "/usr/local/var/run/nginx/client_body_temp/0000000035" failed (13: Permission denied), client:, 

Solution for this error

Change the owner for the folders under /usr/local/var/run/nginx/

For instance, I fixed it with

sudo chown myloginuser:admin -R /usr/local/var/run/nginx

Now I can upload product images. So maybe try this if you encounter this issue.

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.