Jump to content

fopen can't open file.


gmmo1971

Recommended Posts

I think this is more a PHP/linux question, but I will post anyway since I am beginner in PHP/linux.

 

When calling fopen I get this:

 

Warning: fopen(test.txt) [function.fopen]: failed to open stream: Permission denied in /var/www/html/chap10.php on line 82

cannot open file

 

this is using localhost, the wierd part is that it works on my remote web-server.

 

any clues in why PHP fopen failes on my local drive and works remotely?

 

thx!

 

Link to comment
https://forums.phpfreaks.com/topic/106956-fopen-cant-open-file/
Share on other sites

how does it work exactly? Do I have to change the permission of the file. Can I change it globally in some how?

 

I have a similar problem with apache and I posted into their forums but no answer. I am pretty sure is the same problem. Here's what I get, if I try to re-start apache.

 

[root@localhost Date]# /sbin/service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

 

 

"SELinux is preventing /usr/sbin/httpd (httpd_t) "append" to error_log (root_t). The SELinux type %TARGET_TYPE, is a generic type for all files in the directory and very few processes (SELinux Domains) are allowed to write to this SELinux type. This type of denial usual indicates a mislabeled file. By default a file created in a directory has the gets the context of the parent directory, but SELinux policy has rules about the creation of directories, that say if a process running in one SELinux Domain (D1) creates a file in a directory with a particular SELinux File Context (F1) the file gets a different File Context (F2). The policy usually allows the SELinux Domain (D1) the ability to write or append on (F2). But if for some reason a file (error_log) was created with the wrong context, this domain will be denied. The usual solution to this problem is to reset the file context on the target file, restorecon -v error_log. If the file context does not change from root_t, then this is probably a bug in policy. Please file a bug report against the selinux-policy package. If it does change, you can try your application again to see if it works. The file context could have been mislabeled by editing the file or moving the file from a different directory, if the file keeps getting mislabeled, check the init scripts to see if they are doing something to mislabel the file."

 

Apache tries to write a error_log on the root but SELinux complains.

 

anyway, I am new to this whole LAMP thing and any help is greatly appreciated.

 

thx!

 

tchau,

Gustavo.

Link to comment
https://forums.phpfreaks.com/topic/106956-fopen-cant-open-file/#findComment-554147
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.