file($url): failed to open stream: Permission denied

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
syatm
Forum Newbie
Posts: 4
Joined: Mon Sep 03, 2007 6:42 am

file($url): failed to open stream: Permission denied

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Either Apache (usually www-data), or the file/folder does not have the right permissions set.

www.google.com
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Different PHP settings, probably. Is allow_url_fopen enabled on both php settings?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
syatm
Forum Newbie
Posts: 4
Joined: Mon Sep 03, 2007 6:42 am

open($url) permission denied

Post by syatm »

scottayy wrote:Different PHP settings, probably. Is allow_url_fopen enabled on both php settings?
yes, allow_url_fopen is "on".
syatm
Forum Newbie
Posts: 4
Joined: Mon Sep 03, 2007 6:42 am

file($url): failed to open stream: Permission denied

Post 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.
syatm
Forum Newbie
Posts: 4
Joined: Mon Sep 03, 2007 6:42 am

file($url): failed to open stream: Permission denied

Post 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.
Post Reply