CakePHP 2.x warning SplFileInfo due to cakeshell - php

I wrote a cakeshell script which I plan to use it using cronjob. while having run it manually (during testing), sometimes my site will throw SplFileInfo Warning e.g:
Warning: SplFileInfo::openFile(/var/www/flat/app/tmp/cache/persistent/myapp_cake_core_file_map):
failed to open stream: Permission denied in /var/www/flat/lib/Cake/Cache/Engine/FileEngine.php on line 313
Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/models/myapp_cake_model_default_flat_list):
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]
Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/models/myapp_cake_model_default_flat_list) [http://php.net/splfileinfo.openfile]:
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]
Warning (512): _cake_model_ cache was unable to write 'default_flat_list' to File cache [CORE/Cake/Cache/Cache.php, line 309]
Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/persistent/myapp_cake_core_method_cache) [http://php.net/splfileinfo.openfile]:
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]
Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/persistent/myapp_cake_core_method_cache) [http://php.net/splfileinfo.openfile]:
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]
Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/models/myapp_cake_model_default_flat_list) [http://php.net/splfileinfo.openfile]:
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]
Warning (512): SplFileInfo::openFile(/var/www/flat/app/tmp/cache/models/myapp_cake_model_default_flat_list) [http://php.net/splfileinfo.openfile]:
failed to open stream: Permission denied [CORE/Cake/Cache/Engine/FileEngine.php, line 313]
Warning (512): _cake_model_ cache was unable to write 'default_flat_list' to File cache [CORE/Cake/Cache/Cache.php, line 309]
What happened? and how to fix this?
If I check the tmp directory on cache and persistent some of the file are under root permissions. Is this the cause?
[root#Apps103 persistent]# ls
total 40K
-rw-rw-r-- 1 apache 43 Apr 22 17:49 myapp_cake_core_cake_
-rw-rw-r-- 1 root 43 Apr 23 10:01 myapp_cake_core_cake_console_
-rw-rw-r-- 1 root 43 Apr 23 10:01 myapp_cake_core_cake_dev_
-rw-rw-r-- 1 apache 43 Apr 23 10:26 myapp_cake_core_cake_dev_en-us
-rw-rw-r-- 1 apache 43 Apr 23 10:26 myapp_cake_core_cake_en-us
-rw-rw-r-- 1 apache 43 Apr 23 10:26 myapp_cake_core_default_en-us
-rw-rw-r-- 1 root 4.3K Apr 23 10:01 myapp_cake_core_file_map
-rw-rw-r-- 1 root 4.3K Apr 23 10:01 myapp_cake_core_method_cache
I tried the solution from this link SplFileInfo::openFile(/app/tmp/cache/persistent/cake_core_cake_console_):failed to open stream:Permission denied in /lib/.../FileEngine.php line 293
I put this in bootstrap
Cache::config('default', array(
'engine' => 'File',
'mask' => 0666,
));
// short
Cache::config('short', array(
'engine' => 'File',
'duration' => '+1 hours',
'path' => CACHE,
'prefix' => 'cake_short_'
));
// long
Cache::config('long', array(
'engine' => 'File',
'duration' => '+1 week',
'probability' => 100,
'path' => CACHE . 'long' . DS,
));
but it does not work. Usually I clean up the whole tmp directory to remove the warning. then it will work fine again. I'm not sure why, but if I ran the shell, the warning error does not show, until the next day.
My tmp directory (flat/app/tmp) is under apache permission.

What happened?
The tmp folder is normally in the app dir and shared for all requests no matter the origin. A relatively common problem is for tmp files created via a web request to be read-only for console tasks and vice-versa.
If you run cli tasks as root, the tmp files will be created with the owner root - thereafter a webrequest (running by apache) may try to delete from or write to the tmp directory but be unable to modify the existing tmp folder contents as the files are owned by root.
how to fix this?
Either make cli and web requests use different tmp directories - or simply ensure that both cli and web users have write permissions to the tmp directory.
That means either defining the TMP constant before CakePHP does to a place other than app/tmp, e.g. in cake.php:
...
$ds = DIRECTORY_SEPARATOR;
define('TMP', '/tmp/myapp');
...
Or ensure the tmp folder is writable to both users, e.g.:
cd app
chmod -R 777 tmp

Related

Warning: include_once, failed to open stream: Permission denied

Server: Centos 6
I have set permissions on this dev server to 0777 all the way back to the home folder (/home/...)
changed the owner to apache all all files
SELINUX is disabled
Still, when running script from browser, I get:
Warning: include_once(/home/..._somthing.php): failed to open stream:
Permission denied
I can only execute as root from the command line.
help?

failed to open stream wp-settings.php on line 21 fatal error

Warning: require(/home/*******/public_html/wp-includes/load.php): failed to open stream: No such file or directory in /home/******/public_html/wp-settings.php on line 21
Fatal error: require(): Failed opening required '/home/****/public_html/wp-includes/load.php' (include_path='.:/opt/alt/php55/usr/share/pear:/opt/alt/php55/usr/share/php') in /home/******/public_html/wp-settings.php on line 21
Can't see anything of my site and can't login to wordpress panel
but i can access cpanel
last thing i was do edit RTL.css and i undo my edits
Try uploading "load.php" in binary transfer mode.
It could be also a permission problem:
All directories should be 755 or 750.
All files should be 644 or 640. Exception: wp-config.php
should be 440 or 400 to prevent other users on the server from
reading it.

PHP fopen() Error: failed to open stream

I am getting this error when my php script tries to access text file.
PHP Warning: fopen(UPfileName.txt): failed to open stream: Permission denied in /path/to/script.php
Here are the permissions of my directory and file:
abc/www/file.txt
drwxr-xr-x 12 root root abc/
drwxr-xr-x 8 root root www/
-rwxrwxr-x 1 root root file.txt
Please tell what should I do to get ride of this error.
Thanks
Sam

CRON job executing PHP cannot require another file

I have a cron job that runs a php file. Within the php file it requires another file. For other php files run by cron and I do the same require file, it works just file. I've changed permissions on all files involved to 777 (for testing) and the problem still occurs. When I execute the file from the command line, it runs just fine.
Why is the file not allowed permission for this 1 php file?
Here is the error I receive from the cron:
[Fri Mar 29 00:05:01 2013] [warn-phpd] mmap cache can't open /home/rpn/public_html/admin/admin_functions.php - Permission denied (pid 29776)
PHP Warning: require(/home/rpn/public_html/admin/admin_functions.php): failed to open stream: Permission denied in /home/rp/public_html/cron/cron-boxscores.php on line 6
Warning: require(/home/rpn/public_html/admin/admin_functions.php): failed to open stream: Permission denied in /home/rp/public_html/cron/cron-boxscores.php on line 6
PHP Fatal error: require(): Failed opening required '/home/rpn/public_html/admin/admin_functions.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/rp/php') in /home/rp/public_html/cron/cron-scrape-boxscores.php on line 6
Fatal error: require(): Failed opening required '/home/rpn/public_html/admin/admin_functions.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/rp/php') in /home/rp/public_html/cron/cron-boxscores.php on line 6
Here is line 6:
require('/home/rpn/public_html/admin/admin_functions.php');
Here is the directory showing the file and permissions settings:
root#host [/home/rpn/public_html/admin]# ls -l admin*
-rw-r--r-- 1 nobody nobody 19022 Mar 8 14:18 admin_functions.php
nobody:nobody is what Apache is set to run under.

I installed phpfreechat 1.3 on my webpage but I got this errors but I dont know what to do

Warning: copy(/home/beradioc/public_html/phpfreechat-1.3/src/../data/public/themes/default/sound.swf) [function.copy]: failed to open stream: Permission denied in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 179
Warning: chmod() [function.chmod]: Operation not permitted in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 180
Warning: copy(/home/beradioc/public_html/phpfreechat-1.3/src/../data/public/themes/default/smileys/emoticon_surprised.png) [function.copy]: failed to open stream: Permission denied in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 179
Warning: chmod() [function.chmod]: Operation not permitted in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 180
Warning: copy(/home/beradioc/public_html/phpfreechat-1.3/src/../data/public/themes/default/smileys/emoticon_waii.png) [function.copy]: failed to open stream: Permission denied in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 179
Warning: chmod() [function.chmod]: Operation not permitted in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 180
Warning: copy(/home/beradioc/public_html/phpfreechat-1.3/src/../data/public/themes/default/smileys/weather_sun.png) [function.copy]: failed to open stream: Permission denied in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 179
Warning: chmod() [function.chmod]: Operation not permitted in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 180
Warning: copy(/home/beradioc/public_html/phpfreechat-1.3/src/../data/public/themes/default/smileys/weather_cloudy.png) [function.copy]: failed to open stream: Permission denied in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 179
Warning: chmod() [function.chmod]: Operation not permitted in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 180
Your script does not have permissions.
If you are running on your own server, use chmod. If you're running on shared hosting, try chaning permissions anyway, but it's not granted you'll be successful.
chmod is a command for changing permissions on files and/or directories it would appear that your script does not have sufficient permissions to do so, or to copy files around. I would seriously recommend that you study up on file permission, maybe read the READMe for phpfreechat which will probably tell you what those permissions are and go from there. If you do not have ssh access or direct access to your web server, you will probably need some help from your hosting company after you find out what files ad directories need what permissions.
a quick look at phpfreechat's page states:
Give the web server's write permissions to “phpfreechat-x.x/data/public” and “phpfreechat-x.x/data/private” directories.
If you are using FTP:
CHMOD 777 phpfreechat-x.x/data/private
CHMOD 777 phpfreechat-x.x/data/public
If you are using SSH:
chmod 777 phpfreechat-x.x/data/*

Categories