Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a big problem. I have just upgraded to a new dedicated server running Plesk 10, and Ubuntu 11.04 and my scripts can't run file_get_contents or curl to external urls in cgi mode. allow_url_fopen is set to On in the correct php.ini file but still I get the following error.

file_get_contents( failed to open stream: Permission denied

Curl request returns false with this:

function get_data($url)
  // create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);

// grab URL and pass it to the browser
$data = curl_exec($ch);

// close cURL resource, and free up system resources

Both (file_get_contents and curl) run fine in scripts run from command line and from cron and both run fine when php is run as apache module. It is just when running in browser and as a cgi or fastcgi application that the problem arises. I have had the hosting company on all day with no luck. Any help gratefully received.

share|improve this question

It turned out to be SELinux that was causing the problem, I fixed it with this command:

setsebool -P httpd_can_network_connect 1

Thanks to @jsmith in this thread: PHP file_get_contents error on CentOS as he was the second person who had suggested SELinux as causing such problems on centOS. I am a novice so I will only try something when it is confirmed by more than one source.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.