Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following simple test script for cURL/php on a FC12/apache server that has PHP 5.3.2, cURL v7.19.7 (according to phpinfo()):

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/');
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');
curl_exec($ch);
if ($error = curl_error($ch)) {
    echo "Error: $error<br />\n";
}
function read_header($ch, $string)
{
    $length = strlen($string);
    echo "Received $length bytes<br />\n";
    return $length;
}

Now, if I run it through the browser it returns: "Error: Couldn't resolve host 'www.google.com'"

If I run it through my php-cgi command line on the server it returns what you would expect (sans all the BRs):

Header: HTTP/1.1 200 OK
Header: Date: Tue, 13 Jul 2010 20:08:09 GMT
Header: Expires: -1
Header: Cache-Control: private, max-age=0
Header: Content-Type: text/html; charset=ISO-8859-1
Header: Server: gws
Header: X-XSS-Protection: 1; mode=block
Header: Transfer-Encoding: chunked
Header:
Received 2507 bytes
Received 1589 bytes
Received 1362 bytes
Received 2734 bytes
Received 1690 bytes

If I change the google line to google's ip e.g. http://72.14.204.147/ then the script works through the browser as well as through the command line.

dig, ping, nslookup and general dns seem to be working fine on this machine. I should add that DNS for this site is using a subdomain foo.ourdomain.edu and getting it's DNS from a Windows 2003 domain controller.

share|improve this question
    
Fedora hasn't been "Core" for a few years now. –  Ignacio Vazquez-Abrams Jul 13 '10 at 22:31
add comment

1 Answer

You have to enable the httpd_can_network_connect SELinux boolean if you want to allow httpd (which PHP runs as) to make external network connections. See the booleans(8) man page for details.

share|improve this answer
    
getsebool -a | grep httpd_can gives me: httpd_can_network_connect --> on httpd_can_network_connect_db --> on httpd_can_network_relay --> on httpd_can_sendmail --> on still no joy –  chris cohen Jul 14 '10 at 12:50
    
This is somehow a DNS issue, isn't it? Appears clear for me because accessing by IP works from a script. –  whitequark Aug 16 '10 at 11:33
add comment

Your Answer

 
discard

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.