简体   繁体   中英

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)

用于 CLI 的 php conf.d 内部(与 Apache 相同)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM