Page 1 of 1
file($url): failed to open stream: Permission denied
Posted: Mon Sep 03, 2007 6:51 am
by syatm
Hi
I have written a simple php script to read a url.
<?php
$myfile = file('
http://google.com');
foreach ( $myfile as $vals){
print "$vals";
}
?>
I got an error: failed to open stream: Permission denied.
This works on my windows box, but does not work on Linux.
When I type in on a command line like "php -f filename". it works.
Any idea why this does not work?
What configuration do I have change to make this work?
sy
Posted: Mon Sep 03, 2007 9:36 pm
by Zoxive
Either Apache (usually www-data), or the file/folder does not have the right permissions set.
www.google.com
Posted: Mon Sep 03, 2007 10:35 pm
by s.dot
Different PHP settings, probably. Is allow_url_fopen enabled on both php settings?
open($url) permission denied
Posted: Wed Sep 05, 2007 3:18 pm
by syatm
scottayy wrote:Different PHP settings, probably. Is allow_url_fopen enabled on both php settings?
yes, allow_url_fopen is "on".
file($url): failed to open stream: Permission denied
Posted: Wed Sep 05, 2007 3:58 pm
by syatm
[quote="Zoxive"]Either Apache (usually www-data), or the file/folder does not have the right permissions set.
Would you please tell me a bit more specifically about www-data?
Do you mean by that some of my apache directives does not allow reading url?
The script tries to read the url '
http://google.com' using the 'file' function. As long as google's web
page has read permission, it should be fine, isn't it?
I can read the file if the absolute path is specified on my local machine. For example,
file('/var/www/index.html'); // this works, but
file('
http://localhost/index.html'); // failed to open stream: permission denied.
// web root directory is defined "/var/www'
file('
http://google.com'); // failed to open stream: permission denied.
file($url): failed to open stream: Permission denied
Posted: Mon Sep 10, 2007 3:08 am
by syatm
Linux firewall blocked it.
How to fix:
In Fedora 5, select Permissive or Disable from System->Administration->Security
Level and Firewall->SELinux
It does work.