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

Last updated on

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 in the comments if this helped. Follow me on Twitter, Facebook and YouTube.

p.s. I increased my AdSense revenue by 68% using AI 🤖. Read my Ezoic review to find out how.

1 Star2 Stars3 Stars4 Stars5 Stars 3.33 (9 votes)

Leave a Reply

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

We use Markdown to style comments, like on Github and Reddit.
To do a line break, type two spaces after the sentence.
You can add inline code by wrapping it in backticks: `code here`

    To do an entire block of code  
    type four spaces before the line
    and it will appear in a block like this.
    <-- four empty spaces

3 replies

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().

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.

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.