Search code examples
cakephpcakephp-2.0cakephp-2.1

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


I am working on a CakePHP 2 project. It originally started out in 2.0.x and then recently migrated to 2.1.0. Throughout the whole development process, I have been receiving the error message below.

It pops up at the top of the page unpredictably. It can be when I am just viewing different pages, or even after I add a record to the database (yet the record properly saves).

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

I recursively set the owner and group of the tmp folder to apache, and still received the message. In addition, I then recursively set the permissions to read, write, and execute for all (chmod 777). The error message still pops up.

Even after changing both the owner, group, and permissions, the file in question:

cake_prj/app/tmp/cache/persistent/cake_core_cake_console_

will have its owner and group set back to root, and its permissions set back to default.

What could be causing this problem? Is there a way to ensure that every time this file is generated, that it will always have be apache:apache with read/write/execute permissions?


Solution

  • There was a bug report there http://cakephp.lighthouseapp.com/projects/42648/tickets/2172 but it was considered as not being a bug.

    What I personaly noticed is that some file owner may be modified when you use the cake script in the console (for instance to make a bake). The modified files then belong to the user you use in the console.

    Would this mean you call cake while being root ? Or do you have any root cron job that calls a Cake shell script ?

    Personaly I have now the habit to chmod the whole tmp folder content back to the apache user after having used the cake script and it seems to prevent the warning to appear.