cc976a Posted September 10, 2009 Share Posted September 10, 2009 Hope someone can help Having a problem with a website I have that has been moved on to a new server. There is a very strange error message occuring now that did not exist before. It is: Warning: fopen() [function.fopen]: Unable to access ./cache/cache_amazon_ etc.... and then goes on to show the line on the PHP file generating the error. This line is: if ($fp = fopen($filename, 'xb')) { Is this a PHP setting on the server?? :'( Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/ Share on other sites More sharing options...
Daniel0 Posted September 10, 2009 Share Posted September 10, 2009 Probably the permission on the file system. Make sure that the web server has read and write access to that folder. Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916107 Share on other sites More sharing options...
cc976a Posted September 10, 2009 Author Share Posted September 10, 2009 I would guess this is the CHMOD of the folder storing the site? I've never changed this before, and hosted this on a few servers in the past, but certainly going to take a look. Thanks, Dean Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916116 Share on other sites More sharing options...
Daniel0 Posted September 10, 2009 Share Posted September 10, 2009 If you are running on a Unix system, yes, that would be the case. Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916117 Share on other sites More sharing options...
cc976a Posted September 10, 2009 Author Share Posted September 10, 2009 Actually the permission on the old server folder and new server folder are both 755 Looks like something else may be the cause Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916130 Share on other sites More sharing options...
DavidAM Posted September 10, 2009 Share Posted September 10, 2009 from the PHP manual http://us.php.net/manual/en/function.fopen.php If PHP has decided that filename specifies a local file, then it will try to open a stream on that file. The file must be accessible to PHP, so you need to ensure that the file access permissions allow this access. If you have enabled safe mode, or open_basedir further restrictions may apply. Check the settings for safe_mode and open_basedir. Since you moved to a different server, one of these may be causing your problem. Also, $filename seems to be a relative filename. Are you sure it is referring to the file you think it is? Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916138 Share on other sites More sharing options...
cc976a Posted September 10, 2009 Author Share Posted September 10, 2009 Thanks for this. Going to query with the provider... As part of the script: $filename = self::getFilename($group, $id); I know $group and $id are fine. Anything with this that could cause a problem? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916158 Share on other sites More sharing options...
DavidAM Posted September 10, 2009 Share Posted September 10, 2009 I'm not sure, I was kind of hoping the statement would trigger a suggestion from someone who knows a little more the I do. Basically, the error message indicated it was trying to reference ./cache/cache_amazon_ (looks like you truncated it when you posted). The ./ at the beginning indicates the current working directory, which, as I understand, is the path of the main script executing (from the URL). Of course if you changed directories (i.e. chdir() or through some script or system call), it could be referring to another directory. I avoid this issue by always using absolute paths. Since, in general, I know where the file should be. I have defined a constant (C_PHP_ROOT) which is the absolute path of where my scripts are. So to open a file, I might use: $fp = fopen(C_PHP_ROOT . 'cache/whatever.ext'); and then I don't have to worry about not finding the file. You might echo out getcwd() just before the open and see what directory you are in just to know it is the correct one. Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916188 Share on other sites More sharing options...
Daniel0 Posted September 10, 2009 Share Posted September 10, 2009 Actually the permission on the old server folder and new server folder are both 755 Looks like something else may be the cause 755 means that: owner can read, write, execute group can read, execute others can read, execute So, if the file is not owned by the same user that the web server is running as, you will still not be able to write to it. See this: http://en.wikipedia.org/wiki/File_system_permissions#Octal_notation Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916192 Share on other sites More sharing options...
DavidAM Posted September 10, 2009 Share Posted September 10, 2009 Dan'O to the rescue again That was my first thought, and then I second guessed myself. Second guesses are almost always wrong. And octal still confuses me, sometimes. :'( Check the owner and/or group of the files (and directories) and compare that to the user/group that the server is running as. You'll likely have to change one or the other on the files. You do NOT want to make them WORLD writable (i.e. 777). Daniel0, what's the best practice on this, change the group to match the server so the site admin still owns them, or change the owner to the server and set the group? I think the former is better, but I don't have any sites published yet, so I don't have any "real world" experience to base that on. Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916202 Share on other sites More sharing options...
Daniel0 Posted September 10, 2009 Share Posted September 10, 2009 I would do like: chown daniel:www-data -R /path/to/the/files chmod 640 -R /path/to/the/files (assuming the web server is part of the group www-data and my username is daniel) Then I would selectively do: chmod g+w -R someFile1 someFile2 someDir1 someDir2 on files/directories that needs to be writable by the web server. Note that only root can chown. Of course there is no "best" way. Which way is the best depends on your needs. Quote Link to comment https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916209 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.