I have cURL installed on Ubuntu 16 with PHP 7, but I still call the undefined curl_init () function

I did sudo apt-get install curl, sudo apt-get php5-curl, sudo apt-get php-curl, but I get an 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);      
?>
+4
source share
4 answers

Check which version of PHP uses apache using the phpinfo();function.

Verification is important because for some reason you could upgrade to a lower version (as it was in my case).

Now from the 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's 5.6 , use

sudo apt-get install php5.6-curl 

apache2

sudo service apache2 restart
+4

Ubuntu 16.04 php7.0 :

sudo apt-get install php7.0-curl

, , apache

sudo service apache2 reload

+3

, php undefined:

  • php -i | grep EXT_NAME, , , EXT_NAME ( curl) phpinfo(), <?php phpinfo(); ?> , .
  • php -m, , , php -v php.ini find -name 'php.ini' locate php.ini .
  • apache ( ) / , .

3 # apache service apache2 restart

, , , PHP ( , curl) --with-curl[=DIR] .

+2

: phpenmod curl apache. , (;

+1

All Articles