Solved – Fatal error: Call to undefined function curl_init

This is a common error that occurs whenever PHP’s curl extension has not been installed or enabled.

The error will read something like this:

Fatal error: Call to undefined function curl_init()

Essentially, PHP can’t find the curl_init function because the extension that defines it has not been loaded. This results in a fatal error, which kills the PHP script.

Check to see if curl is enabled.

To see if your PHP installation has curl enabled, you can run the following code:

The phpinfo function above will output information about PHP’s configuration.

If you do a CTRL + F search for curl and nothing is found, then it means that your PHP installation does not have curl enabled. If you do find it, then you should see the following line under the curl heading:

cURL support: enabled

Note that you should NOT leave this phpinfo function on a live web server, as it outputs sensitive information about your PHP installation!

Enabling curl on Linux.

If your web server is running on Linux and you have SSH / terminal access, you can make sure that curl is installed by running the following command:

After running the command above, you will need to restart your web server so that the changes will take effect.

If you are using Apache, you can restart your web server like so:

If you are using Nginx, you can use the following command:

After your web server has been restarted, curl should be enabled.

Enabling curl on Windows.

If you are using Windows, you will need to locate the php.ini file that is being used by your web server. If you are unsure about which php.ini file you need to edit, then you can use the phpinfo script that we used above, as that will display the full path to the file that is being used by the web server.

Once you have located your php.ini file, you will need to “uncomment” the following line:

To uncomment the line above and enable the php_curl.dll extension, simply remove the semi-colon at the beginning.

After you have saved the changes that you made to your php.ini file,  you will need to restart your web server. Otherwise, the new configuration will not take effect.

Enabling curl on WampServer.

If you are using the popular WampServer program on Windows, then you can try the following steps:

  1. Click on the WampServer icon in your system tray.
  2. Hover over the “PHP” option.
  3. Once the PHP menu appears, hover over the “PHP extensions” option.
  4. At this stage, a list of PHP extensions should appear. If an extension has a tick beside it, then it is already enabled. If the php_curl option does not have a tick beside it, then it is not enabled. To enable curl, simply click on the php_curl option.
  5. WampServer should automatically restart Apache and the changes should take effect.
  6. If WampServer does not automatically restart Apache, then you can manually force it to do so by clicking on the “Restart All Services” option in the main menu.

Hopefully, this guide helped you to get rid of that nasty “undefined function curl_init” error!

Related: Sending a POST request without cURL.

Facebook Comments