Question

I have working CakePHP 2.5.dev app and I have disabled cache in CakePHP via

Configure::write('debug', 2);
Configure::write("Cache.disable", true);

in app/Config/core.php

Unfortunately I must deploy this app to a server where I can't write into app/tmp directory.

I checked answers on StackOverflow how to disable cache and above lines into app/Config/core.php and even commented-out rest lines which are responsible for caching ie

/**
 * Configure the cache used for general framework caching. Path information,
 * object listings, and translation cache files are stored with this configuration.
 */
//Cache::config('_cake_core_', array(
//  'engine' => $engine,
//  'prefix' => $prefix . 'cake_core_',
//  'path' => CACHE . 'persistent' . DS,
//  'serialize' => ($engine === 'File'),
//  'duration' => $duration
//));

/**
 * Configure the cache for model and datasource caches. This cache configuration
 * is used to store schema descriptions, and table listings in connections.
 */
//Cache::config('_cake_model_', array(
//  'engine' => $engine,
//  'prefix' => $prefix . 'cake_model_',
//  'path' => CACHE . 'models' . DS,
//  'serialize' => ($engine === 'File'),
//  'duration' => $duration
//));

But when I run my app on production server, I get an exception.

Warning: /home/kowalski_m/public_html/projekt2/app/tmp/cache/persistent/ is not writable in /home/kowalski_m/public_html/projekt2/lib/Cake/Cache/Engine/FileEngine.php on line 384

Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured.' in /home/kowalski_m/public_html/projekt2/lib/Cake/Cache/Cache.php:181 Stack trace: #0 /home/kowalski_m/public_html/projekt2/lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('_cake_core_') #1 /home/kowalski_m/public_html/projekt2/app/Config/core.php(376): Cache::config('_cake_core_', Array) #2 /home/kowalski_m/public_html/projekt2/lib/Cake/Core/Configure.php(72): include('/home/kowalski_...') #3 /home/kowalski_m/public_html/projekt2/lib/Cake/bootstrap.php(175): Configure::bootstrap(true) #4 /home/kowalski_m/public_html/projekt2/app/webroot/index.php(94): include('/home/kowalski_...') #5 /home/kowalski_m/public_html/projekt2/index.php(41): require('/home/kowalski_...') #6 {main} thrown in /home/kowalski_m/public_html/projekt2/lib/Cake/Cache/Cache.php on line 181

enter image description here

So it looks like caching is still working.

I can't get write laws for this directory in this server. I don't have access to root.

How can I disable totally caching and setup CakePHP to don't write anything into /app/tmp ?

Was it helpful?

Solution

Do you have APC installed on your server?

If so, then you can use this to cache the core. This is faster than hitting the filesystem anyway.

You WILL need those lines configuring the cake_core, just be sure to set

$engine = 'Apc';

above the cache configuration lines.

If using APC on a shared server, it's important to set your prefix properly, I use the following config which works on shared hosting with multiple cake apps installed:

Cache::config(
    '_cake_core_',
    array(
        'engine' => $engine,
        'prefix' => $prefix . 'cake_core_' . Inflector::slug(ROOT),
        'path' => CACHE . 'persistent' . DS,
        'serialize' => ($engine === 'File'),
        'duration' => $duration
    )
);

Alternatively:

You don't need root access to set permissions for that folder, all you need is FTP access. You can set the permissions for app/tmp/* to 777 using FTP, which is what I do for some other temporary folders that I use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top