Sergiu
Sergiu

Reputation: 21

Fatal error: Uncaught Zend_Cache_Exception: cache_dir ".../var/page_cache" is not writable in .../zendframework1/library/Zend/Cache.php on line 209

I have the following configuration:

CentOS VM x64 with mysql 5.7 and php 7.0.10

As for my web server I use nginx with php-fpm.

So I've installed magento from the git repo, branch 2.1, and I keep getting this error:

Fatal error: Uncaught Zend_Cache_Exception: cache_dir "/usr/share/nginx/html/var/page_cache" is not writable in /usr/share/nginx/html/vendor/magento/zendframework1/library/Zend/Cache.php on line 209

I tried changing the owner of the magento / directory recursively from nginx to php-fpm, then I tried giving 777 permission to the page_cache directory, but nothing seems to happen, same error no matter what I try.

The only reason I see this error is because I added the syntax ini_set('display_errors', 1); to the main index file, otherwise I wold see a bank page. Changing magento to developer mode did nothing regarding showing any errors on the page, also renaming the file local.xml.sample to local.xml did nothing in showing the error that I'm facing.

Upvotes: 0

Views: 10132

Answers (1)

Alana Storm
Alana Storm

Reputation: 166116

I'd start with an ls -lh on your cache dir and its parent to make sure you have 777 permissions on everything you think you do.

Failing that - the Zend Exception you're seeing originates here:

# File: vendor/magento/zendframework1/library/Zend/Cache/Backend/File.php
public function setCacheDir($value, $trailingSeparator = true)
{
    if (!is_dir($value)) {
        Zend_Cache::throwException(sprintf('cache_dir "%s" must be a directory', $value));
    }
    if (!is_writable($value)) {
        Zend_Cache::throwException(sprintf('cache_dir "%s" is not writable', $value));
    }
    if ($trailingSeparator) {
        // add a trailing DIRECTORY_SEPARATOR if necessary
        $value = rtrim(realpath($value), '\\/') . DIRECTORY_SEPARATOR;
    }
    $this->_options['cache_dir'] = $value;
}

So for whatever reason, PHP's is_writable function is returning false when passed that cache dir. Checkout's is_writable's PHP manual entry and work through the comments there for possible edge cases. One possibility from the first comment

To Darek and F Dot: About group permissions, there is 
this note in the php.ini file:

; By default, Safe Mode does a UID compare check when
; opening files. If you want to relax this to a GID compare,
; then turn on safe_mode_gid.
safe_mode_gid = Off

Upvotes: 1

Related Questions