PHP Fatal error: Uncaught Error: Call to undefined function curl_init()

Last updated on | 5 replies

cURL is a PHP extension used to transfer data to or from a remote server. If the extension is not installed or enabled on your web server, you may get a fatal PHP error about an undefined function curl_init().

Shared Hosting

If you are on shared hosting and do not have command line access to your web server or access to php.ini, you may have to contact your web host to see if they support the cURL PHP extension. Many web hosts disable this extension by default for security reasons but may enable it manually for you on request.

Install cURL extension for Apache/Nginx on Linux

If you have shell access to your Apache or Nginx web server, make sure the cURL extension is installed:

sudo apt-get install php-curl

You must also restart your web server for changes to take effect.

To restart Apache, run:

sudo service apache2 restart

To restart Nginx, run:

sudo service nginx restart

Now test cURL with:

curl google.com

If you see some HTML, cURL is working correctly.

Check php.ini

If cURL is installed but you are still getting “Call to undefined function curl_init()”, you may need to enable the extension in your php.ini file.

Firstly, locate your php.ini file: Where is my PHP php.ini Configuration File Located?

In the example below, we are editing the php.ini file for Apache with PHP 7.2.

sudo nano /etc/php/7.2/apache2/php.ini

Press CTRL + W and search for curl.

Remove the ; semicolon from the beginning of the following line. This line may look different depending on your version of PHP, just remove the semicolon.

php.ini
;extension=curl

To save file and exit, press CTRL + X, press Y and then press ENTER.

You must restart your web server for changes to take effect.

To restart Apache, run:

sudo service apache2 restart

To restart Nginx, run:

sudo service nginx restart

Now test cURL with:

curl google.com

If you see some HTML, cURL is working correctly.

Windows

If you’re on Windows, go to your php.ini file and search for “curl”.

Remove the ; semicolon from the beginning of the following line.

php.ini
;extension=curl

If you are on an older version of PHP, the line might look like below.

php.ini
;extension=php_curl.dll

After you have saved the file you must restart your HTTP server software before this can take effect.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

5 replies

Leave a reply

Your email address will not be published. Required fields are marked *

  1. thanks. it work.
    btw. did you know how to make array zero.
    I mean like this

    $variable = [];

    but when I run it. it get error.

  2. this works for me.:
    sudo apt-get install php-curl

    all other sites says to run commands, change php.ini, that did not work for me.

    Thanks you for posting this.

  3. I also have the same issue.
    Checked using phpinfo() and cURL is listed.
    Using php -m, curl is listed.
    Checked php.ini both on php and apache and it is enabled.
    Checked on wamp > php > extensions it is also checked but still Call to undefined function curl_init().

  4. After upgrading to PHP 7.3.8 and with extension=php_curl.dl correctly enabled in my php.ini, I still receive the error: “Fatal error: Uncaught Error: Call to undefined function curl_init()”. Strange.

    1. Run php -m. Is curl listed? if not, make sure you are editing the correct php.ini file. Try locate php.ini to find it. Also make sure to restart your web server after editing php.ini.