Not able to open a file in php
- by ehsanul
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