Search code examples
cakephpamazon-ec2croncakephp-3.xcakephp-3.4

CakePHP 3 Cache File Permissions


I have a CakePHP 3 app with shells that I run from crontab.

When I run the shells through crontab, it creates cache files owned by the user running the crontab, which is not the user that runs apache...

Sometimes when I run the crontab the cached models are owned by apache and the shell fails, sometimes when I visit a page the models are owned by ec2-user and the page fails...

I posted a question on github, https://github.com/cakephp/cakephp/issues/11265#issuecomment-333951638

I was told to modify the chmod option for the cache config, I tried the following but it didn't work...

/**
 * Configure the cache adapters.
 */
'Cache' => [
    'default' => [
        'className' => 'File',
        'path' => CACHE,
        'url' => env('CACHE_DEFAULT_URL', null),
        'chmod' => 777
    ],

Any ideas on how I can make the default file permissions 777 on the cake cache files?


Solution

  • I would suggest having the chron run as the correct user OR having the chron task change owner and keep permissions as set but if you really want to have it all as it is and just change the permissions then you can use the mask option which I assume is what they meant.

    Cache Config Options

    Set using the following:

    'Cache' => [
        'default' => [
            'mask' => 0777,
            // other config options
        ],
    ]