3

I've been working on a site for about a month and I recently tried to bake something and now I'm really stuck with the cache permission problem that just popped up. I've read everything on stackoverflow on this issue for example:

SplFileInfo::openFile(/app/tmp/cache/persistent/cake_core_cake_console_):failed to open stream:Permission denied in /lib/.../FileEngine.php line 293

Cakephp Permission denied Fileengine.php

Including the bug/non-bug: http://cakephp.lighthouseapp.com/projects/42648/tickets/2172

But I still can not stop this error from appearing during a plugin's load of a javascript asset using the HTML->script helper.

Warning: SplFileInfo::openFile(/var/www/2tli/app/tmp/cache/persistent/myapp_cake_core_cake_console_): failed to open stream: Permission denied in /var/www/2tli/lib/Cake/Cache/Engine/FileEngine.php on line 314

Call Stack: 0.0009 352948 1. {main}() /var/www/2tli/app/webroot/index.php:0

0.0045     446644   2. include('/var/www/2tli/lib/Cake/bootstrap.php') /var/www/2tli/app/webroot/index.php:92

0.0327    1174292   3. Configure::bootstrap() /var/www/2tli/lib/Cake/bootstrap.php:171

0.0427    1406772   4. include('/var/www/2tli/app/Config/core.php') /var/www/2tli/lib/Cake/Core/Configure.php:78

0.0494    1512200   5. Cache::config() /var/www/2tli/app/Config/core.php:336

0.0495    1512940   6. Cache::_buildEngine() /var/www/2tli/lib/Cake/Cache/Cache.php:136

0.0562    1635708   7. FileEngine->gc() /var/www/2tli/lib/Cake/Cache/Cache.php:169

0.0562    1635796   8. FileEngine->clear() /var/www/2tli/lib/Cake/Cache/Engine/FileEngine.php:102

0.0617    1637516   9. FileEngine->_setKey() /var/www/2tli/lib/Cake/Cache/Engine/FileEngine.php:236

0.0627    1657060  10. trigger_error() /var/www/2tli/lib/Cake/Cache/Engine/FileEngine.php:314

I am running PHP 5.3.10. Cake 2.3.7. I have the following in my bootstrap.php:

// Setup a 'default' cache configuration for use in the application.
Cache::config('default', array('engine' => 'File', 'mask' => 0666));

And in core.php:

/**  
* 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,
                'mask'=>0666 ));

    Cache::config('_cake_model_', array(
        'engine' => $engine,
        'prefix' => $prefix.'cake_model_',
        'path' => CACHE . 'models' . DS,
        'serialize' => ($engine === 'File'),
        'duration' => $duration,
        'mask' => 0666
));

My plugin also has a bootstrap.php with:

Cache::config('UserPlugin', array(
    'engine' => 'File',
    'duration'=> '+3 months',
    'path' => CACHE,
    'prefix' => 'UserPlugin_',
            'mask'=>0666
));

I have put all the app/tmp files and folders as my apache owner www-data and set to 777 (I also tried 666 to match the mask).

I've deleted and rebuilt the app/tmp directory too.

Does anyone have any ideas?

EDIT: I don't know quite what to make of this, but I noticed the commenting out the Html->script helper sometimes wouldn't remove the error (and the raw html still showed the include for the script). So I stared deleting caches and setting the cache duration time down to 1 second. Only occasionally did it behave as expected because the html seemed cached. The only way I found to consistently get it to work as expected (either when commenting in or out the line) was to delete the cache and restart the browser (firefox). Then whenever I would put in the html->script again after restarting firefox, cake would work without the permission error. I'm sure the problem will come back, because I can't seem to find the root cause.

Community
  • 1
  • 1
user6972
  • 851
  • 1
  • 15
  • 32
  • Have you included model, view and persistent subfolders in your app/tmp/cache directory? – joshua.paling Aug 21 '13 at 00:14
  • @joshua.paling Yes with www-data and 777. I'm really stuck on this one... – user6972 Aug 21 '13 at 00:28
  • Do you definitely have free space left on your server? Can you create files inside those directories manually, over plain FTP? – joshua.paling Aug 21 '13 at 01:13
  • Yes and after more testing only seems to be happening when the html helper is trying to read my ajaxValidation.js script. When cake loads it the error is inserted into the beginning of the js file. I can see this using firebug and click on the js link. The error is there followed by the proper js. (the js file looks fine and about 4 others load fine too) It's strange because this has been working fine for a month and a few bake cycles. This last time seemed to break it. – user6972 Aug 21 '13 at 01:35

2 Answers2

5

The problem that I found with Bake doing this is that the permissions where limited on the files in my persistant cache. This means the my website created them (www-data) and didn't give the full read/write/execute permissions for my console app to use that file.

I fixed this by changing the permissions on the files in that persistent folder

cd ./app/tmp/cache/persistent/
sudo chmod 777 *  

I had to use sudo since I wasn't the owner of the files; the website (www-data) was.

Hope this helps someone.

ZombieCode
  • 1,646
  • 2
  • 24
  • 46
  • I just deleted the "tmp" directory and all its contents, and let the application re-create it. Yes, I did need to "sudo" for a couple of files, but that was it. It may not be the most elegant solution, but it seems to work. BTW, I see this question came up for CakePHP version 2.3 which has been EOL for a while, and here we are in CakePHP version 4.3, and it still hasn't been fixed. – UncaAlby Aug 15 '23 at 04:34
0

It is still unclear to me what is happening on my system however I've confirmed that closing the browser and restarting it fixes this issue.

I am testing on my local system with Firefox 23.0, using firebug & firephp.

In addition I've found that if I add a $this->Js->link via a helper in a view that has been previously rendered, the new JS script will not appear until the browser is stopped and restarted. (Does not matter if cakephp caches are cleared or not.)

I don't know if this is some kind of firefox/firebug or apache or cake problem.

EDIT: I've also found that moving this file to app/webroot/js instead of serving it through the plugin works 100% of the time. Perhaps there is a bug in how the asset is getting served by cake?

user6972
  • 851
  • 1
  • 15
  • 32