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

女生的网名这么多〃 提交于 2019-11-28 18:47:15

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.

You can resolve this by adding a mask to your config in core.php

Cache::config('default', array(
    'engine' => 'File',
    'mask' => 0666,
));

Instead of setting giving read/write access to everyone on the tmp/cache directory I did this:

chgrp -R www-data app/tmp
chmod -R g+rw app/tmp 
find app/tmp -type d -exec chmod g+s {} \;

Setting the group of the directories to the Apache user and then setting the setgid bit will allow you to ensure that files created in that directory get the proper group permissions regardless of what user runs the shell script. This also allows you to exclude read/write permissions to "other" users.

dav

I think the reason of the problem is already explained, as the cron runs under root user and created files in tmp are not accessible by web user. The other solutions did not work for me and I did not want to set tmp permissions to 777, I ended up setting a cron job for the web user, in debian specifically it would be

crontab -u www-data -e

Taken from this answer How to specify in crontab by what user to run script?

If you're encountering the SplFileInfo error in CakePHP2 and you're absolutely certain that your file/directory permissions are set up properly, then one other thing to check is your PHP version. Cake2 requires PHP 5.2.8 or greater and although you'd usually be alerted on the default page if you were using the wrong version, you wouldn't be alerted if you'd developed your app on one server and then moved it to another.

I experienced this error after developing a Cake2 app on a PHP5.3 server and then moving it to a PHP 5.1 server. Upgrading to 5.2.17 (which is above 5.2.8) solved the problem.

Ashish

Use this ..

cd cakephp/app/tmp/cache/persistent 

sudo chmod 666 myapp*

cd ..

cd models

sudo chmod 666 myapp*

You need to make the app/tmp directory writable by the webserver. Find out what user your webserver runs as (in my case _www) and change the ownership of the app/tmp directory to that user: $ chown -R _www app/tmp

Another solution. Permission conflicting occurred because multi users share same files. Thus, if we split cache directory into multi sub directories, no conflicting occur and no changing default permission of directories and files required.

As following, each sub cache directory is defined by type of php api handler:

define('CACHE', TMP . 'cache' . DS . php_sapi_name() . DS);
  • When browser the website, active user is apache. And the sub directory is cache/apache2handler.
  • When run a batch, active user is root or logging-in user. And the sub directory is cache/cli.

Other side, current user account can be used to name sub directory. Check at How to check what user php is running as?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!