1

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)

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.