How to resolve cURL Error (7): couldn't connect to host? How to resolve cURL Error (7): couldn't connect to host? xml xml

How to resolve cURL Error (7): couldn't connect to host?


CURL error code 7 (CURLE_COULDNT_CONNECT)

is very explicit ... it means Failed to connect() to host or proxy.

The following code would work on any system:

$ch = curl_init("http://google.com");    // initialize curl handlecurl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);$data = curl_exec($ch);print($data);

If you can not see google page then .. your URL is wrong or you have some firewall or restriction issue.


“CURL ERROR 7 Failed to connect to Permission denied” error is caused, when for any reason curl request is blocked by some firewall or similar thing.

you will face this issue when ever the curl request is not with standard ports.

for example if you do curl to some URL which is on port 1234, you will face this issue where as URL with port 80 will give you results easily.

Most commonly this error has been seen on CentOS and any other OS with ‘SElinux’.

you need to either disable or change ’SElinux’ to permissive

have a look on this one

http://www.akashif.co.uk/php/curl-error-7-failed-to-connect-to-permission-denied

Hope this helps


If you have tried all the ways and failed, try this one command:

setsebool -P httpd_can_network_connect on