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);
?>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With