Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

"Cache directory is not writable" error.

Hello all.

I recently applied a cache to a slow performing page:

    // My DI setup.

    $di->set('modelsCache', function() use ($config) {

        //Cache data for one day by default
        $frontCache = new \Phalcon\Cache\Frontend\Data(array(
            "lifetime" => 3600

        $cache = new \Phalcon\Cache\Backend\File($frontCache, array(
             "cacheDir" => $config->application->cacheDir,

        return $cache;

    // My find
    $this->view->orders = Orders::find([
        "status = 'complete'", 
        'order' => 'updated DESC', 
        'limit' => 300, 
        'cache' => ['lifetime' => 120, 'key' => 'archive-page']

I have logged in to the server and run chmod 0777 and still no joy. My volt is working fine in that folder and $config->application->cacheDir is also employed in the di setup. The cace is also working fine in my local WAMP; I can see a file name "archive-page" in my local cache folder. Anyone?


Try it recursively (chmod 0777 -R) and from different folders inside your server folder.

Yep that did it but I don't understand why the volt engine is able to write to the cache folder (and sub folders for pdf and email templates) when the folders are set to 0775 but the model cache requires the whole cache structure to be 0777?


Maybe Phalcon is linked to Ẁorld permission, so probably that's the cause.

edited Sep '14

Never set the permissions of 777.

Operation "write cache" does volts, but on behalf of the server.

User can set cache directory in 2 stage :

  1. Set owner of your server user (see config of your server) or
$ ps -elf | grep apache

$ ps -elf | grep nginx


$ ps -elf | grep lighttpd

For example, you see your server user is http.

Then :

$ sudo chown http:http cache/
  1. Set permissions
$ sudo chmod 750 cache/

All commands soulld be execution with empty cache/ directory.

After set server should to write files to cache with owner http and permissions 644.

Of course, your cache/ directory should not be in your server public structure.

For clear cache you can use command :

$ sudo rm -rf /path_to_cache/cache/*

Indeed you are right to point out that the cache shouldn't be set to 777. Don't want to make people think that by accepting that answer. My bad. I accepted it because I tried it and it exposed the problem to me but I havn't left it that way.