Call to undefined function curl_init in Laravel
In this tutorial, we will discuss the Call to the undefined function curl_init in Laravel. This error is a common error that occurs whenever PHP’s curl extension has not been enabled or installed.
The error will something like this:
Fatal error: Call to undefined function curl_init()
First, check if curl is enabled.
<?php
// The phpinfo function above will output information about PHP's configuration related.
// Call the phpinfo function.
phpinfo();
CTRL + F to search for curl and nothing is found. Now it means that your PHP installation does
not have curl enabled.
cURL support: enabled
Enabling curl on Windows.
Go to your php.ini file and remove the ;(semi-colon) mark from the beginning.
#D:\xampp\php\php.ini #Old php_curl ;extension=php_curl.dll #New php_curl extension=php_curl.dll
Now you have saved the changes that you made to your php.ini file and restarted your web server before this can take effect.
Enabling curl on Linux.
Your web server is running on Linux and you have SSH/terminal access. So make sure that curl is installed by the following command:
sudo apt-get install php-curl
If you’re using PHP5.
sudo apt-get install php5-curl
Or specific PHP version
sudo apt-get install php5.6-curl
After running the command, you will need to restart the web server. then the changes will take effect.
If you are using Apache
sudo service apache2 restart
If you are using Nginx
sudo service nginx restart