提交工单

PHP提示缺少扩展怎么办?安装php-mbstring、php-gd、php-intl等扩展

常见的报错形式

PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen()
Your requirements could not be resolved ... requires ext-intl

WordPress 后台「工具 → 站点健康」也会提示缺少的模块。

函数和扩展的对应关系

报错中的函数 / 名称 需要的扩展
mb_* mbstring
imagecreate*、图片处理 gd 或 imagick
curl_* curl
simplexml_*、DOMDocument xml
ZipArchive zip
Normalizer、IntlDateFormatter intl
mysqli_*、PDO MySQL mysql
Redis 对象缓存 redis

安装(Ubuntu / Debian)

先确认 PHP 版本:

php -v
ls /etc/php/

安装扩展时带上版本号,保证装到正在使用的那个版本上:

apt install php8.3-mbstring php8.3-gd php8.3-intl php8.3-zip php8.3-curl php8.3-xml -y

让它生效

PHP-FPM 需要重启:

systemctl restart php8.3-fpm

确认

php -m | grep -i intl            # 命令行
php-fpm8.3 -m | grep -i intl     # FPM

常见的坑

装到了别的 PHP 版本上:服务器上有多个 PHP 版本,apt install php-intl 可能装到了默认版本,而网站用的是另一个版本,见 一台服务器安装多个 PHP 版本。

命令行和网站的结果不一样:CLI 和 FPM 是两套配置,扩展装好后两边都检查一下。

面板用户:宝塔、1Panel 中在 PHP 设置里点选安装扩展即可。

WordPress 推荐的扩展

一般建议至少安装:curl、gd(或 imagick)、intl、mbstring、mysql、xml、zip,Redis 缓存需要 redis 扩展。LNMP 环境的完整安装见 Ubuntu 搭建 LNMP 环境。