I have cURL installed on Ubuntu 16 with PHP 7 but i get still Call to undefined function curl_init()
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
:
- Run
php -i | grep EXT_NAME
to see the output if the regex matches anything that hasEXT_NAME
(in above casecurl
) in yourphpinfo()
or simply make a test file with<?php phpinfo(); ?>
and see if you spot the extension. - Run
php -m
to see loaded extensions and check if you have another installation that is taking precedence viaphp -v
or more than one php.ini file usingfind -name 'php.ini'
orlocate php.ini
in the root directory. - 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.
Related videos on Youtube
AceJordan
Updated on June 04, 2022Comments
-
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 almost 8 yearsi 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 almost 8 years@AceJordan you might need to disable mod php5 and enable php7 via:
a2dismod php5
and thena2enmod php7.0
thenservice apache2 restart
-
Ekin almost 8 yearsThat of course requires you to install
libapache2-mod-php7.0
first. -
trank almost 8 yearstry enabling php7 mod like @Ekn's comment and specify php version in
phpenmod
command like:phpenmod -v 7.0 curl
-
Confused over 7 yearsI 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