Dasher Labs
Dasher Labs

Reputation: 99

PHP CLI Fatal error: Call to undefined function curl_init()

I am trying to run a PHP script from the CLI (command line interface) and get this error as if PHP curl is not loaded.

Fatal error: Call to undefined function curl_init()

I have been looking and tried many solutions on here and no results.

What I have done

  1. Updated PHP
  2. Updated Linux system
  3. Installed php-curl extension
  4. Copied over Apache php.ini to cli/php.ini

What does work

  1. Running curl_init from Apache (web request)
  2. Running the command: php5 -q file.php (This works but I get another error regarding the class Thread not being loaded, but seems curl_init should be easier to fix)

Inside php conf.d for CLI (All the same as Apache)

Upvotes: 1

Views: 1630

Answers (1)

JohnC
JohnC

Reputation: 3287

(php 7.4, ubuntu 20.04)

I was getting "Uncaught Error: Call to undefined function" in an unfamiliar library.

I retested with a simple code snippet and got the same error.

<?php
    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, "http://www.php.net");
    curl_exec ($curl);
    curl_close ($curl);
?>

I installed php curl sudo apt-get install php-curl and retested.

That fixed the problem.

Upvotes: 1

Related Questions