why curl extension_loaded shows false instead curl is exist

Viewed 62

I am using a linux system and curl is installed already in my system. When I check curl version in terminal curl --version then output is below

curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smtp smtps telnet tftp 
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP

When I use this code in my application

var_dump(extension_loaded('curl'));

Output shows bool(false)

Even when I send some test data

$url = "my_url/?text=Test Data";

//$url = "www.google.com";

sendDataToUrl($url);

And my function is

function sendDataToUrl($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT,1);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

This function is not working. But same function is working in another linux server. I don't know what actual root cause and why don't working send data function?

Please help me to identify the root cause

1 Answers

First you have to mind that curl or apache default curl and php curl are two different things. First you have to install your php version related curl. Like if you use php version 5 then you have to install php5-curl

Open SSH

First Install CURL by typing sudo apt-get install curl

Then Restart Apache by typing sudo service apache2 restart

Then Install PHP5 CURL by typing sudo apt-get install php5-curl

will prompt to install… type y or yes!

Then Restart Apache by typing sudo service apache2 restart Done!

For details, please see this Documentation

Hope It will fix your problem

Related