cancel
Showing results for 
Search instead for 
Did you mean: 

cache dir is not writable - centos 7 nginx magento 2.4

cache dir is not writable - centos 7 nginx magento 2.4

I have tried for many hours to resolve this issue but no success, please see the attached image.

To test I have given /var/ folder and all inside 777 permissions, but I still receive this not writable error.

Could anyone assist?

error.jpg

4 REPLIES 4

Re: cache dir is not writable - centos 7 nginx magento 2.4

@matt_ryding I can not see your image however I will try to resolve your issue. It related to permission, so you can reset it by

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find var pub/static pub/media app/etc generated/ -type f -exec chmod g+w {} \;
find var pub/static pub/media app/etc generated/ -type d -exec chmod g+ws {} \;
chown -R <Magento user>:<web server group> .
chmod u+x bin/magento

As '777' permission is not recommended.

 

Please let me know if issue not solved

Re: cache dir is not writable - centos 7 nginx magento 2.4

Hi Shrinet,

 

Thank you for your response below, I have followed these steps but the error persists, please see below.

 

[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_1cmiqs
Nothing to import.
[magento@code public_html]$ ls
app               bin           composer.json  COPYING.txt  generated                 Gruntfile.js.sample  lib              LICENSE.txt        package.json.sample  pub          setup  vendor
auth.json.sample  CHANGELOG.md  composer.lock  dev          grunt-config.json.sample  index.php            LICENSE_AFL.txt  nginx.conf.sample  phpserver            SECURITY.md  var
[magento@code public_html]$ find . -type f -exec chmod 644 {} \;
[magento@code public_html]$ find . -type d -exec chmod 755 {} \;
[magento@code public_html]$ find var pub/static pub/media app/etc generated/ -type f -exec chmod g+w {} \;
[magento@code public_html]$ find var pub/static pub/media app/etc generated/ -type d -exec chmod g+ws {} \;
[magento@code public_html]$ chown -R magento:magento .
[magento@code public_html]$ chmod u+x bin/magento

After changing the permissions as per above, when browsing to the new Magento 2.4 install at code.printivart.com.au the following Nginx error is received:

 

2020/10/03 03:44:33 [error] 9070#0: *22 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Zend_Cache_Exception: cache_dir "/opt/magento/public_html/var/page_cache" is not writable in /opt/magento/public_html/vendor/magento/zendframework1/library/Zend/Cache.php:209
Stack trace:
#0 /opt/magento/public_html/vendor/magento/zendframework1/library/Zend/Cache/Backend/File.php(180): Zend_Cache::throwException()
#1 /opt/magento/public_html/vendor/colinmollenhour/cache-backend-file/File.php(87): Zend_Cache_Backend_File->setCacheDir()
#2 /opt/magento/public_html/vendor/magento/zendframework1/library/Zend/Cache.php(153): Cm_Cache_Backend_File->__construct()
#3 /opt/magento/public_html/vendor/magento/zendframework1/library/Zend/Cache.php(94): Zend_Cache::_makeBackend()
#4 /opt/magento/public_html/vendor/magento/framework/App/Cache/Frontend/Factory.php(156): Zend_Cache::factory()
#5 /opt/magento/public_html/vendor/magento/framework/Cache/Frontend/Adapter/Zend.php(38): Magento\Framework\App\Cache\Frontend\Factory->Magento\Framework\App\Cache\Frontend\{closure}(" while reading response header from upstream, client: 220.235.87.89, server: code.printivart.com.au, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/run/php-fpm/magento.sock:", host: "code.printivart.com.au"

Even when setting /opt/magento to permissions 777 the above error is still received.

 

Do you have any idea what the cause of this error may be?

 

 

Edit: Incase it helps, here is the Nginx server block config:

 

/etc/nginx/conf.d/code.printivart.com.au.conf

upstream fastcgi_backend {
  server   unix:/run/php-fpm/magento.sock;
}

server {
    listen 80;
    server_name code.printivart.com.au;

    include snippets/letsencrypt.conf;
    return 301 https://code.printivart.com.au$request_uri;
}

server {
    listen 443 ssl http2;
    server_name code.printivart.com.au;

    ssl_certificate /etc/letsencrypt/live/code.printivart.com.au/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/code.printivart.com.au/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/code.printivart.com.au/chain.pem;
    include snippets/ssl.conf;

    set $MAGE_ROOT /opt/magento/public_html;
    set $MAGE_MODE developer; #or production

    #access_log /var/log/nginx/code.printivart.com.au-access.log;
    #error_log /var/log/nginx/code.printivart.com.au-error.log;

    include /opt/magento/public_html/nginx.conf.sample;
}

/etc/php-fpm.d/magento.conf

[magento]
user = magento
group = nginx
listen.owner = magento
listen.group = nginx
listen = /run/php-fpm/magento.sock
pm = ondemand
pm.max_children =  50
pm.process_idle_timeout = 10s
pm.max_requests = 500
chdir = /      

 

software versions:

[magento@code public_html]$ bin/magento --version
Magento CLI 2.4.0
[magento@code public_html]$ php -v
PHP 7.4.11 (cli) (built: Sep 29 2020 10:17:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies
[magento@code public_html]$ nginx -v
nginx version: nginx/1.16.1
[magento@code public_html]$ 

Re: cache dir is not writable - centos 7 nginx magento 2.4

Hello @matt_ryding ,

please go through the following link for permissions

https://devdocs.magento.com/guides/v2.3/install-gde/prereq/file-system-perms.html,

also, check the following link for the solution

https://magento.stackexchange.com/a/255374/72475

 

Thank You.

Re: cache dir is not writable - centos 7 nginx magento 2.4

Thank you Smita

To confirm, I have resolved the issue, solution below

Permissions were set correct, the issue was selinux enforcing

 

After following the guide below everything was working correct

https://devdocs.magento.com/guides/v2.4/install-gde/prereq/security.html