That Brazilian Guy
That Brazilian Guy

Reputation: 3531

Zend Cache Exception: 'cache_dir "/home/(...)/application/../data/tmp/" is not writable'

I'm really new to Zend, few days of use.

I'm getting a fatal error message:

Fatal error:  Uncaught exception 'Zend_Cache_Exception' with message 'cache_dir "/home/[REDACTED]/application/../data/tmp/" is not writable' in /home/[REDACTED]/library/Zend/Cache.php:209
Stack trace:
#0 /home/[REDACTED]/library/Zend/Cache/Backend/File.php(181): Zend_Cache::throwException('cache_dir "/hom...')
#1 /home/[REDACTED]/library/Zend/Cache/Backend/File.php(129): Zend_Cache_Backend_File->setCacheDir('/home/user/Proj...')
#2 /home/[REDACTED]/library/Zend/Cache.php(153): Zend_Cache_Backend_File->__construct(Array)
#3 /home/[REDACTED]/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('File', Array, false, false)
#4 /home/[REDACTED]/application/Bootstrap.php(42): Zend_Cache::factory('Core', 'File', Array, Array)
#5 /home/[REDACTED]/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initCache()
#6 /home/[REDACTED]/library/Zend/Applica in /home/[REDACTED]/library/Zend/Cache.php on line 209

According to the error message, I would expect a folder permissions issue on the tmp directory. The directory is, however, writable:

user@[REDATCED]:~/[REDATCED]/data$ ls -hal
total 24K
drwxrwxr-x  6 user user 4,0K Jan  7 18:40 .
drwxr-xr-x 12 user user 4,0K Jan  9 12:50 ..
drwxrwxr-x  3 user user 4,0K Dez 17 11:42 locales
drwxrwxr-x  2 user user 4,0K Dez 17 11:42 logs
drwxrwxr-x  2 user user 4,0K Dez 17 11:42 sessions
drwxrwxr-x  2 user user 4,0K Jan  7 18:40 tmp

The workaround is to comment the following lines on application/Bootstrap.php:

    protected function _initCache() {
          $frontendOptions = array(
              'lifetime' => 7200, // cache lifetime of 2 hours
              'automatic_serialization' => true
          );

          $backendOptions = array(
              'cache_dir' => APPLICATION_PATH . '/../data/tmp/' // Directory where
          );

          // getting a Zend_Cache_Core object
          $this->cache = Zend_Cache::factory('Core', 'File',
            $frontendOptions, $backendOptions);

          Zend_Registry::set('cache', $this->cache);

          Zend_Date::setOptions(array(
              'cache' => $this->cache
          ));

This workaround was suggested by a coworker, I have no idea what I'm doing here or even if this code is part of Zend or our codebase. I don't like ugly hacks, or "fixing" stuff by commenting out code, or doing anything without knowing what I'm doing, or the reason behind it.

Besides, the code seems to be working on my coworkers' machines. And every time I pull their code commits from the repository I get an uncommented copy anyway.

I probably could exclude the file from the repository or anything like that (I'm new to git as well), but I really prefer:

Upvotes: 1

Views: 13326

Answers (3)

kay
kay

Reputation: 337

This error typically occurs because of permissions.

To solve this, if you're using apache as your web server, assign ownership to apache.

On my Fedora Core machine I solved this by simply issuing:

chown my_current_name:apache -R /var/www/project_name 

Upvotes: 5

Aravind
Aravind

Reputation: 11

Had the same issue, solved it by following a simple step. lib>Zend>Cache>Backend>File.php find this line

protected $_options = array(
'cache_dir' => 'null',

Remove the quote and leave it as

protected $_options = array(
'cache_dir' => null, 

It really worked for me.

Upvotes: 1

That Brazilian Guy
That Brazilian Guy

Reputation: 3531

As I was writing this question I noticed my mistake, the tmp directory is writable by myself and other users of the same group, apparently Zend will access the files as another user. The solution was to chmod 777 on the folder, making it writable.

Upvotes: 1

Related Questions