You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 16.04下PHP 7.2安装php-curl失败及curl_init()报错求助

环境信息
  • 系统:Ubuntu 16.04
  • PHP版本:PHP 7.2.34
  • NGINX版本:nginx/1.10.3 (Ubuntu)
问题

安装PHP 7.2的curl扩展时遇到失败,尝试多种命令均无法解决。

已尝试操作及错误

尝试1:通过Ondrej PPA安装php7.2-curl

执行命令:

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

报错输出:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php7.2-curl
E: Couldn't find any package by glob 'php7.2-curl'
E: Couldn't find any package by regex 'php7.2-curl'

尝试2:安装通用php-curl包

执行命令:

sudo apt-get update
sudo apt 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.0-curl but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
解决方案
  1. 修复PPA源与缓存
    Ubuntu 16.04已终止官方支持,Ondrej的PPA可能存在源同步问题,先重新配置PPA:
sudo add-apt-repository --remove ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update --allow-insecure-repositories
  1. 修复破损依赖
    先解决系统中已存在的破损包问题:
sudo apt-get install -f
sudo dpkg --configure -a
sudo apt-get autoremove --purge
  1. 安装php7.2-curl
    尝试直接安装,若仍找不到包,先搜索可用版本:
apt-cache show php7.2-curl | grep Version

然后使用找到的版本号安装(示例版本号需替换为实际搜索结果):

sudo apt install php7.2-curl=7.2.34-1+ubuntu16.04.1+deb.sury.org+1
  1. 验证安装结果
    执行以下命令确认curl扩展已加载:
php -m | grep curl

输出curl即表示安装成功。

内容的提问来源于stack exchange,提问作者rencie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 11:35:36