在 CentOS 上配置 PHP 时,所需扩展取决于你的应用场景(如 Web 网站、API、队列、数据库连接等)。下面按常见必装、按需选择分类说明,并给出 CentOS 安装方式(以 PHP 7.4 / 8.x 为例,使用 Remi 或 CentOS 自带源)。
php-cli
php-fpm
php-common
php-json
php-mbstring
php-zip
php-gd
php-curl
php-opcache
作用:
cli / fpm:命令行 & Web 运行mbstring:中文/多字节字符串curl:HTTP 请求gd:图片处理zip:压缩opcache:性能加速php-mysqlnd
# 或
php-pdo
php-mysqli
php-pecl-redis
php-pecl-mongodb
php-xml
php-dom
php-session
php-bcmath
php-intl
用途:
xml / dom:接口、SOAPbcmath:金额计算intl:国际化php-pecl-swoole # 协程
php-pecl-memcached
php-pecl-amqp # RabbitMQ
php-pecl-imagick # 高级图片处理
yum install -y epel-release
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php81
yum install -y php php-fpm php-mysqlnd php-redis php-gd php-mbstring php-curl
php -m
php -i | grep extension_dir
普通网站(Laravel / ThinkPHP)
php-fpm php-mysqlnd php-redis php-gd php-mbstring php-zip php-xml php-bcmath opcache
API / 微服务
php-fpm php-redis php-curl php-json opcache
如果你告诉我:
我可以给你精准扩展清单 + 配置文件示例。