codeigniter - Could not resolve host - Can't get cURL to work with php on nginx


I have Digitalocean LEMP application dropplet configured to host my website (PHP - CodeIgniter application), I'm using Nexmo SMS API in my application and everything worked well until today. Suddenly, now when I try to send SMS I have this error "Could not resolve host:". Looks like cURL is not working, but when I checked if it is installed - it is, and my phpinfo shows it as well. I restarted nginx, php5-fpm, tried some different curl settings in my code but always got this error.

When I tried to run simple script like this:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '');
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');
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;

result is still "Error: Could not resolve host:" so i think the problem is in cURL and not in my application code (i'm using NEXMO CodeIgniter library).

I tried everything that comes in my mind and now I'm running out of ideas, so every help is appreciated. Are there any special settings/things to do to connect/make cURL works with nginx that I'm missing? Maybe something in nginx.conf files, or do I need to open some ports, etc?




Note that the error is "Could not resolve host". This points not to curl, but to the system resolver library. Curl does not, by itself, do DNS lookups, but instead uses the system standard methods, usually using libresolv. If you use a system call trace utility like strace you will see that the resolver is then controlled by /etc/nsswitch.conf, /etc/host.conf and /etc/resolv.conf. Your first point of call should be there. You can test that it is system and not curl by using a standard PHP file call, like:

$web_content = file_get_contents("");

This should return the body if it can resolve the host.

People are also looking for solutions to the problem: php - Apostrophe not working in OpenJS Grid


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.