php fopen error on fedora 21

178 views Asked by At

I am getting the following permissions warning with a while reading a file:

PHP Warning: fopen(todo.txt): failed to open stream: Permission denied in /var/www/php/oauth/web/insert.php on line 26, referer: https://oauth.dev/dropbox_finish.php?state=5

This problem come just by executing this code:

try{
   $f = fopen("todo.txt", "r+");
...
}

I have done a lot of things with the permissions, let me show the current ones and then I'll show the rest.

[root@windows8 abel]# ls -lah /var/www/php
total 32K
drwxr-xr-x. 8 abel apache 4.0K Jun  3 15:53 .
drwxr-xr-x. 6 root root   4.0K May 29 12:38 ..
drwxr-xr-x. 3 abel abel   4.0K May 25 11:38 backup
drwxr-xr--. 6 abel apache 4.0K May 28 16:00 oauth
drwxr-xr-x. 8 abel apache 4.0K Apr 16 16:22 teamerp
drwxrwxr-x. 2 abel abel   4.0K Apr 16 17:18 TeamERP
drwx------. 5 abel abel   4.0K Apr 27 17:14 wordpress
drwx------. 6 abel abel   4.0K Jun  3 15:55 wp-test
[root@windows8 abel]# ls -lah /var/www/php/oauth/
total 36K
drwxr-xr--. 6 abel apache 4.0K May 28 16:00 .
drwxr-xr-x. 8 abel apache 4.0K Jun  3 15:53 ..
drwxr-xr--. 2 abel apache 4.0K Jun  7 11:56 app
-rwxr-xr--. 1 abel apache  124 May 25 16:05 composer.json
-rwxr-xr--. 1 abel apache 3.5K May 25 16:19 composer.lock
-rwxr-xr--. 1 abel apache    9 May 23 12:39 .gitignore
drwxrwxr-x. 3 abel apache 4.0K May 24 17:54 nbproject
drwxr-xr--. 5 abel apache 4.0K May 25 16:19 vendor
drwxr-xr--. 4 abel apache 4.0K Jun  8 15:16 web
[root@windows8 abel]# ls -lah /var/www/php/oauth/web/
total 36K
drwxr-xr--. 4 abel apache 4.0K Jun  8 15:16 .
drwxr-xr--. 6 abel apache 4.0K May 28 16:00 ..
drwxrwxr-x. 2 abel apache 4.0K May 28 16:00 css
-rw-rw-r--. 1 abel apache 5.4K Jun  8 17:37 dropbox_finish.php
-rwxr-xr--. 1 abel apache  109 May 28 09:59 index.php
-rw-rw-r--. 1 abel apache 1.3K Jun  8 17:50 insert.php
drwxrwxr-x. 2 abel apache 4.0K Jun  7 11:36 js
-rwxrwxrwx. 1 abel apache   55 Jun  8 17:50 todo.txt
[root@windows8 abel]# 

The file is todo.txt.It has 777 permissions, the website works, but this file is supposed to be open to write it. That is the only difference as compared to any other if the html and php files that apache is serving.

The user abel is a member of the apache group. I have also tried to make the file owned by the user apache and it did not work, besides apache can read the rest of the web files, it's just this-one. Any hint?

EDIT: I have created a folder and put the file inside. the run the following:

echo substr(sprintf('%o', fileperms('todo/todo.txt')), -4);

the result is 0777. I do not know what is going on, php actually sees the file, but I am still getting the error.

EDIT2: I have also execute the following command to know if it was a selinux problem with the file. semanage fcontext -a -t httpd_sys_rw_content_t /var/www/php/oauth/web/todo/todo.txt

No results.

0

There are 0 answers