Facing a file permission error while running CakePHP in Ubuntu 10.4

I've faced similar problems. Here are a couple of things that helped me:

If you don't want to use the "sledgehammer" approach of chmod 777 (you may want to avoid it on production, for instance), the CakePHP installation instructions provide details on how to use ACL instead:

  • For Cake 2: http://book.cakephp.org/2.0/en/installation.html#permissions
  • For Cake 3: http://book.cakephp.org/3.0/en/installation.html#permissions

Note that you'll probably need to use sudo for the setfacl commands given there.

However, in my experience (CakePHP 2), those commands aren't enough. These commands give your webserver user access to the cache etc, but anything you run from the command line (like the cake command) will probably be running as your user rather than the webserver user.

Therefore, you should run the setfacl commands linked to above a second time, replacing ${HTTPDUSER} with your user name. If you're not sure what your username is, type whoami to find it.


I have encountered a very similar problem with cachePhp 3.

Warning (512): /cache/persistent/ is not writable [CORE/src/Cache/Engine/FileEngine.php, line 439]

Warning (512): Cache engine Cake\Cache\Engine\FileEngine is not properly configured. [CORE/src/Cache/Cache.php, line 177]

Because I am new in CakePhp, I have debuged the file with problem - CORE/src/Cache/Engine/FileEngine.php. Here is function like next:

protected function _active()
{
    $dir = new SplFileInfo($this->_config['path']);
    $path = $dir->getPathname();

    $success = true;
    if (!is_dir($path)) {        
        //@codingStandardsIgnoreStart
        $success = @mkdir($path, 0775, true);
        //@codingStandardsIgnoreEnd
    }

    $isWritableDir = ($dir->isDir() && $dir->isWritable());

    if (!$success || ($this->_init && !$isWritableDir)) {
        $this->_init = false;
        trigger_error(sprintf(
            '%s is not writable',
            $this->_config['path']
        ), E_USER_WARNING);
    }

    return $success;
}

It checks if cache directory is writable and get data about path form $this->_config['path'] variable. This variable is initialized by default from .env file (if you use it), and it has lines like next:

export CACHE_DEFAULT_URL="File://tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}"
export CACHE_CAKECORE_URL="File://tmp/cache/persistent?prefix=${APP_NAME}_cake_core&serialize=true&duration=${CACHE_DURATION}"
export CACHE_CAKEMODEL_URL="File://tmp/cache/models?prefix=${APP_NAME}_cake_model&serialize=true&duration=${CACHE_DURATION}"

I have changed all File: to Null:, like next:

export CACHE_DEFAULT_URL="Null://tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}"
export CACHE_CAKECORE_URL="Null://tmp/cache/persistent?prefix=${APP_NAME}_cake_core&serialize=true&duration=${CACHE_DURATION}"
export CACHE_CAKEMODEL_URL="Null://tmp/cache/models?prefix=${APP_NAME}_cake_model&serialize=true&duration=${CACHE_DURATION}"
export CACHE_DRV_DEFLT = "Null"
export CACHE_DRV_MODEL = "Null"
export CACHE_DRV_CORE = "Null"

And it helps, my problem was fixed. Probably it will be helpfull for someone. Enjoy!


The command sudo chmod -R 777 cakephp/app/tmp only made tmp writable, you should make cache and it's subdirectories writable as well, otherwise Cake can't write the cache files to the cache directory in tmp.

So, these directories should be writable:

cakephp/app/tmp/cache
cakephp/app/tmp/cache/persistent
cakephp/app/tmp/cache/models

Make sure the log directory is writable as well: cakephp/app/tmp/logs.