Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/173793-php-cache-help/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916138
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916188
Share on other sites

Actually the permission on the old server folder and new server folder are both 755

 

Looks like something else may be the cause  :confused:

 

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

Link to comment
https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916192
Share on other sites

Dan'O to the rescue again  :D

 

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.

Link to comment
https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916202
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/173793-php-cache-help/#findComment-916209
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.