Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have problem regarding zend cache_dir. I try to tranfer my site from one server to another, and it work. But, when i try to access the site, it shows this error:

PHP Fatal error:  Uncaught exception 'Zend_Cache_Exception' with message 'cache_dir "/tmp" must be a directory' in /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php:209
Stack trace:

- #0 /home/aiesorgm/public_html/gcpi/library/Zend/Cache/Backend/File.php(178): Zend_Cache::throwException('cache_dir "/tmp...')
- #1 /home/aiesorgm/public_html/gcpi/library/Zend/Cache/Backend/File.php(129): Zend_Cache_Backend_File->setCacheDir('/tmp')
- #2 /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php(153): Zend_Cache_Backend_File->__construct(Array)
- #3 /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('File', Array, false, false)
- #4 /home/aiesorgm/public_html/gcpi/application/Bootstrap.php(55): Zend_Cache::factory('Page', 'File', Array, Array)
- #5 /home/aiesorgm/public_html/gcpi/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initCache()
- #6 /home/aiesorgm/public_html/gcpi/library/Zend/Application/Bootstrap/BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract-> in /home/aiesorgm/public_html/gcpi/library/Zend/Cache.php on line 209

I already try all solutions that i can get from stackoverflow, but it's still doesn't work. I also have create tmp directory inside public folder and change the permission to 777.

application/Bootstrap.php

protected function _initCache() {
    $info = Zend_Registry::get('info');

    $backendOptions = array(
        'cache_dir' => sys_get_temp_dir(),
        'hashed_directory_level' => 1,
        'file_name_prefix' => 'style',
        'automatic_cleaning_factor' => 1
    );
    $frontendOptions = array(
        'lifetime' => $info['cache']['lifetime'],
        'automatic_serialization' => true,
        'caching' => ($info['cache']['enabled'] == '1') ? true : false,
    );
    $cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
    Zend_Registry::set('cache', $cache);
}

/library/Zend/Cache/Backend/File.php

    protected $_options = array(
    'cache_dir' => null,
    'file_locking' => true,
    'read_control' => true,
    'read_control_type' => 'crc32',
    'hashed_directory_level' => 0,
    'hashed_directory_perm' => 0700,
    'file_name_prefix' => 'zend_cache',
    'cache_file_perm' => 0600,
    'metadatas_array_max_size' => 100
);

Folder Structure

application

  • config
  • controller
  • form
  • layouts
  • models
  • view

docs

library

public

  • css
  • js
  • images
  • tmp
  • .htaccess
  • index.php

10Q for your time for reading this.

share|improve this question
add comment

1 Answer

/tmp is the full path, so ZF isn't trying to write to a folder called tmp in your public folder, it's trying to write to the system temp folder at the root of the file system.

I'd recommend setting a project-specific cache folder instead:

$backendOptions = array(
    'cache_dir' => APPLICATION_PATH.'/../data/cache',
    'hashed_directory_level' => 1,
    'file_name_prefix' => 'style',
    'automatic_cleaning_factor' => 1
);

then create a folder called data within your project, and a cache folder within that, and make it writeable.

share|improve this answer
    
Hello Tim, thanks for your solution. it work like a charm. Thanks again :D –  zienil nazwan Feb 17 at 7:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.