php 7.4 中未安装 php-curl

php 7.4 中未安装 php-curl

我正在尝试在终端中安装 php-curl,但是此命令显示

    linux@Lenovo:~$ sudo apt-get install php-curl 

    Reading package lists... Done Building dependency tree       
Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:
        
        The following packages have unmet dependencies:  
    php-curl : Depends: php7.4-curl but it is not going to be installed 
    E: Unable to correct problems, you have held broken packages.

答案1

您可以通过 ondrej/php PPA 添加它:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.4-curl

答案2

sudo apt update
sudo apt install php7.4-curl
sudo service apache2 restart

答案3

AskUbuntu 上发布了许多有关 PHP 旧功能(例如 CURL)和用于 SQL 数据库访问的面向过程的函数的问题,这些问题在 Ubuntu 20.04 和 PHP 7.4 上无法运行。

看起来,更现代功能的倡导者选择弃用较旧的功能实现,即使 PHP 文档中没有任何内容暗示这些功能已被弃用。这些较旧的接口由许多现有应用程序使用,因此应该在受支持的存储库中,或者清除必须提供指向受支持的替代方案的指针,这需要重写代码以符合现代标准。特别是 PHP 文档中没有关于curl_init表明这是不是这是 PHP 的一个标准功能,也是在互联网上交换信息的推荐方式。甚至没有提到stream_context_create可以与 fopen、readfile 或 SplFileObject 一起使用。例如,除了 curl_...,您还可以使用以下内容,该内容改编自 stream_context_create 文档页面的贡献:

$opts = array(
        'http' => array (
            'method'=>"POST",
            'header'=>
              "Accept-language: en\r\n".
              "Content-type: application/x-www-form-urlencoded\r\n",
            'content'=>http_build_query(array('foo'=>'bar'))
  )
);

$context = stream_context_create($opts);

$fp = fopen('https://www.example.com', 'r', false, $context);

在我看来,显然这也是为 Ubuntu 20.04 打包做出贡献的人们的观点,使用较新的界面会更加清晰。我刚刚在 curl_init 的 PHP 文档中添加了一条用户贡献的说明。

相关内容