Ubuntu PHP 5安装Curl找不到软件包

时间:2019-06-21 15:24:29

标签: php curl php-curl

我遇到了PHP致命错误:

Call to undefined function curl_init() error while testing some PHP code on my server.

我认为需要安装Curl,因此我首先找到了PHP版本:

php --version
PHP 5.6.11-1ubuntu3.4 (cli)

我继续安装软件包:

sudo apt-get install php5-curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php5-curl

然后我尝试:

sudo apt install php-curl

它似乎已安装,但我看到了对PHP 7的引用,并成功完成了该操作。

但是,问题仍然存在。

如何使curl运行以停止init()错误?

更新:运行此命令时,我得到:

sudo apt-get install curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
curl is already the newest version (7.47.0-1ubuntu2.13).
0 upgraded, 0 newly installed, 0 to remove and 172 not upgraded.

2 个答案:

答案 0 :(得分:1)

您正在使用Ubuntu@16.04。 16.04不随php @ 5一起提供,但随php @ 7一起提供。

如果您需要较早版本的php及其依赖项,则必须以不同的方式安装它。

有一个由ondrej维护的trustworthy(注:任何外部存储库可能仍然是安全线程)存储库,即:

我已经使用16.04构建了一个Dockerfile,以展示如何安装php@5.6和php5.6-curl:

FROM ubuntu:16.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update && \
    apt-get -qq install software-properties-common > /dev/null && \
    LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php -y > /dev/null && \
    apt-get -qq update && apt-get -qq install php5.6 php5.6-curl > /dev/null
RUN php -v && php -m | grep curl

此Dockerfile并不理想,但最后一次运行打印:

PHP 5.6.40-8+ubuntu16.04.1+deb.sury.org+1 (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
curl

表明它已安装php@5.6和php-curl@5.6。

答案 1 :(得分:0)

尝试:

  1. 首先通过键入12/345 12345 安装CURL。
  2. 然后通过键入sudo apt-get install curl重新启动Apache。
  3. 安装PHP5 CURL sudo service apache2 restart
  4. 通过键入sudo apt-get install php5-curl重新启动Apache。