Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have cURL installed on Ubuntu 16 with PHP 7 but i get still Call to undefined function curl_init() [duplicate]

I have done sudo apt-get install curl, sudo apt-get php5-curl, sudo apt-get php-curl but i get undefined function for curl_init()

does anyone know any solutions for this?

Here is my PHP code.

<?php 
    // create curl resource 
    $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, "example.com"); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output = curl_exec($ch); 

    // close curl resource to free up system resources 
    curl_close($ch);      
?>
like image 672
AceJordan Avatar asked Jun 09 '16 04:06

AceJordan


1 Answers

Check what version of PHP is apache using ,By using phpinfo(); function.

Checking is important because you might have switched to lower version for any reason (Like it was in my case).

Now from command line run this command to install curl

*(Don\'t copy this) sudo apt-get install php[version of php]-curl* 

For example if it is 5.6 then use

sudo apt-get install php5.6-curl 

After that, don't forget to restart apache2

sudo service apache2 restart
like image 185
Confused Avatar answered Sep 23 '22 14:09

Confused