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

16,018

Solution 1

For Ubuntu 16.04 running php7.0, you should specify the version like so:

sudo apt-get install php7.0-curl

Then, as always, restart apache with

sudo service apache2 reload

Solution 2

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

Solution 3

Try this: phpenmod curl and restart apache. Hope this help (;

Solution 4

For anyone having a similar issue when installing a php extension and still getting undefined:

  1. Run php -i | grep EXT_NAME to see the output if the regex matches anything that has EXT_NAME (in above case curl) in your phpinfo() or simply make a test file with <?php phpinfo(); ?> and see if you spot the extension.
  2. Run php -m to see loaded extensions and check if you have another installation that is taking precedence via php -v or more than one php.ini file using find -name 'php.ini' or locate php.ini in the root directory.
  3. Don't forget to restart apache (or any other similar service) and/or enable if you have installed a module.

3# for apache can be done via running service apache2 restart

If you're building from source another possible cause might be that you forgot to recompile PHP with (again, in this case curl) --with-curl[=DIR] after installing an extension.

Share:
16,018

Related videos on Youtube

AceJordan
Author by

AceJordan

Updated on June 04, 2022

Comments

  • AceJordan
    AceJordan almost 2 years

    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);      
    ?>
    
  • AceJordan
    AceJordan almost 8 years
    i tried this and I got this result 'Module curl ini file doesn't exist under /etc/php/5.6/mods-available.' , i guess it's getting curl in the wrong directory since i'm using PHP 7
  • Ekin
    Ekin almost 8 years
    @AceJordan you might need to disable mod php5 and enable php7 via: a2dismod php5 and then a2enmod php7.0 then service apache2 restart
  • Ekin
    Ekin almost 8 years
    That of course requires you to install libapache2-mod-php7.0 first.
  • trank
    trank almost 8 years
    try enabling php7 mod like @Ekn's comment and specify php version in phpenmod command like: phpenmod -v 7.0 curl
  • Confused
    Confused over 7 years
    I was facing same issue with installed php7 curl.. But when i checked I found that the enable php version was 5.6 So it is for some1 who might face same