ttocskcaj Posted May 20, 2012 Share Posted May 20, 2012 I'm trying to open a URL using fopen() and I keep getting this error: Failed to open stream: Permission denied I can not work out what is wrong, it's not a firewall as far as I can tell. Quote Link to comment https://forums.phpfreaks.com/topic/262809-trying-to-open-url-functionfopen-failed-to-open-stream-permission-denied/ Share on other sites More sharing options...
kicken Posted May 20, 2012 Share Posted May 20, 2012 Check your phpinfo() output and make sure that allow_url_fopen is enabled. If it is and you still get the error, then you are probably running on a SELinux setup which disables php's ability to open sockets when run under apache. You either need to change the SELinux configuration to allow that or disable SELinux all together. Some google searches should turn up the howto for each of those options. Quote Link to comment https://forums.phpfreaks.com/topic/262809-trying-to-open-url-functionfopen-failed-to-open-stream-permission-denied/#findComment-1346963 Share on other sites More sharing options...
creata.physics Posted May 20, 2012 Share Posted May 20, 2012 PHP Manual said this: If PHP has decided that filename specifies a local file, then it will try to open a stream on that file. The file must be accessible to PHP, so you need to ensure that the file access permissions allow this access. If you have enabled safe mode, or open_basedir further restrictions may apply. So if safe_mode or oben_basedir is enabeld then you'll have some issues and there are some workarounds, though I think if safe mode is on you'll get an error specific to that.. Also, please double check your permissions, I don't think it is likely that this issue is related to actual code. It's most likely going to have to do with permissions, just like the error states. This is of course in addition to kickens post, so start of with what he suggested. Quote Link to comment https://forums.phpfreaks.com/topic/262809-trying-to-open-url-functionfopen-failed-to-open-stream-permission-denied/#findComment-1346964 Share on other sites More sharing options...
ttocskcaj Posted May 20, 2012 Author Share Posted May 20, 2012 How would file permissions come into it? I'm talking about opening a URL. I'll try that kicken Quote Link to comment https://forums.phpfreaks.com/topic/262809-trying-to-open-url-functionfopen-failed-to-open-stream-permission-denied/#findComment-1346965 Share on other sites More sharing options...
PFMaBiSmAd Posted May 20, 2012 Share Posted May 20, 2012 Posting the actual fopen statement and the url you are trying to use would help. xxxxxx out any part of the url you don't want to post, but don't change any of the actual syntax you are using. Quote Link to comment https://forums.phpfreaks.com/topic/262809-trying-to-open-url-functionfopen-failed-to-open-stream-permission-denied/#findComment-1347002 Share on other sites More sharing options...
ttocskcaj Posted May 21, 2012 Author Share Posted May 21, 2012 $url = "http://113.21.224.170:20059/api/call?method=runConsoleCommand&args=%5B%22manuadd%20Jack%20Admin%22%5D&key=XXXX"; $h = fopen($url,'r'); Quote Link to comment https://forums.phpfreaks.com/topic/262809-trying-to-open-url-functionfopen-failed-to-open-stream-permission-denied/#findComment-1347202 Share on other sites More sharing options...
ttocskcaj Posted May 21, 2012 Author Share Posted May 21, 2012 If it is and you still get the error, then you are probably running on a SELinux setup which disables php's ability to open sockets when run under apache. You either need to change the SELinux configuration to allow that or disable SELinux all together. Some google searches should turn up the howto for each of those options. You were right. SELinux was blocking apache from network access. Running this command fixed it. # /usr/sbin/setsebool -P httpd_can_network_connect 1 Quote Link to comment https://forums.phpfreaks.com/topic/262809-trying-to-open-url-functionfopen-failed-to-open-stream-permission-denied/#findComment-1347212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.