温馨提示×

centos php配置支持curl吗

小樊
42
2026-09-05 22:32:22
栏目: 编程语言

在 CentOS 上,PHP 默认不一定自带 curl 支持,通常需要单独安装对应的扩展。

一、检查 PHP 是否已支持 curl

执行以下命令之一:

php -m | grep curl

或

php -i | grep curl

如果有输出(如 curl => enabled),说明 已支持 curl。


二、CentOS 安装 PHP curl 扩展

1️⃣ 使用 yum(系统自带 PHP)

yum install php-curl

安装后重启 Web 服务:

systemctl restart httpd      # Apache
# 或
systemctl restart nginx php-fpm

2️⃣ 使用 remi 源(推荐,版本较新)

yum install phpXX-php-curl
# 例如 PHP 7.4
yum install php74-php-curl

然后重启:

systemctl restart php74-php-fpm

3️⃣ 编译安装 PHP(源码)

在 ./configure 时加上:

--with-curl

三、验证

<?php
var_dump(function_exists('curl_version'));
?>

输出 bool(true) 即表示支持。


四、常见问题

  • ❌ Call to undefined function curl_init()
    → 没装 php-curl 或未重启服务
  • ❌ 使用宝塔 / lnmp
    → 在面板或 lnmp 脚本中开启 curl 模块

如果你能告诉我:

  • CentOS 版本(7 / 8 / Stream)
  • PHP 安装方式(yum / 源码 / 宝塔 / lnmp)

我可以给你更精确的命令。

0 踩