Not able to open a file in php

Posted by ehsanul on Stack Overflow See other posts from Stack Overflow or by ehsanul
Published on 2010-04-12T08:58:26Z Indexed on 2010/04/12 9:03 UTC
Read the original article Hit count: 349

Filed under:
|
|
|
|

The following code works when invoking through the command line with php -f test.php, from root. It does not work though when being invoked via apache when loading the php page. The code chokes at fopen() and the resulting web page just says "can't open file".

<?php 
  $fp = fopen("/path/to/some_file.txt","a") or die("can't open file");
  fwrite($fp,"some text");
  fclose($fp);
?>

I tried to play with the file permissions, but to no avail. I changed the user/group with chown apache:apache test.php and changed permissions with chmod 755 test.php. Here is the relevant result of ls -l /path/to/some_file.txt:

-rwxr-xr-x 1 apache apache 0 Apr 12 04:16 some_file.txt

© Stack Overflow or respective owner

Related posts about php

Related posts about apache