项目运行过程中,可能需要额外的扩展支持,这时我们不可避免要去安装动态扩展
bash
# 使用 phpize 初始化 configure 配置文件时,需要 autoconf 依赖库
apt install autoconf -yini
# /server/php/84/lib/php.ini
extension=redis
extension=mongodb
extension=yaml
extension=apcu
;zend_extension=opcache
zend_extension=xdebug
[xdebug]
# xdebug.mode=off
xdebug.mode=develop,coverage,debug,gcstats,profile,trace
xdebug.client_host=127.0.0.1
# xdebug.client_host=192.168.66.254
xdebug.client_port=9084ini
# /server/php/74/lib/php.ini
extension=redis
extension=mongodb
extension=yaml
extension=apcu
;zend_extension=opcache
zend_extension=xdebug
[xdebug]
# xdebug.mode=off
xdebug.mode=develop,debug,trace
xdebug.client_host=127.0.0.1
# xdebug.client_host=192.168.66.254
xdebug.client_port=9074bash
# 加入环境变量的php版本
php --ri xdebug
php --ri redis
php --ri mongodb
php --ri yaml
php --ri apcubash
/server/php/74/bin/php --ri xdebug
/server/php/74/bin/php --ri redis
/server/php/74/bin/php --ri mongodb
/server/php/74/bin/php --ri yaml
/server/php/74/bin/php --ri apcu注意
在测试环境(Debian12 发行版)中安装 php-7.4.33 的 PECL 扩展,需要 使用特定版本的 Autoconf 来生成 configure 文件!
使用特定版本的 Autoconf
测试环境(Debian12 发行版)使用 /server/php/74/bin/phpize 生成 configure 文件时,通常会出现警告, 这是因为系统自带的 Autoconf 版本为 2.71,从 php-7.4.33 源码包的 configure 文件开头可以看到, PHP 自身是使用 Autoconf-2.69 来生成 configure 文件的:
ini
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for PHP 7.4.33.
...我们可以自己从 Autoconf 官网 下载指定版本的包,并编译到自己的服务器上, 再将环境变量 $PATH 的首个检查路径设为 “刚刚编译的 Autoconf 的 bin 目录下” 这样可以确保使用该版本。
bash
# 公共依赖库,请使用root账户编译
mkdir /server/autoconf-2.69
cd /root/autoconf-2.69
./configure --prefix=/server/autoconf-2.69
make -j4 > make.log
make installbash
# 修改 $PATH 首个检查路径
export PATH=/server/autoconf-2.69/bin:$PATH1. xdebug 扩展
xdebug 扩展安装案例:
bash
cd /home/php-fpm/php_ext/xdebug-3.4.2
phpize
./configure --with-php-config=/server/php/84/bin/php-config
make -j4 > make.log
make installini
# 如果 Xdebug 和 OPCache 同时使用,xdebug 必须在 opcache 之后:
zend_extension=opcache
zend_extension=xdebug
[xdebug]
# xdebug.mode=off
xdebug.mode=develop,coverage,debug,gcstats,profile,trace
xdebug.client_host=127.0.0.1
# xdebug.client_host=192.168.66.254
xdebug.client_port=9084bash
cd /home/php-fpm/php_ext/xdebug-3.1.6
/server/php/74/bin/phpize
./configure --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make installini
# 如果 Xdebug 和 OPCache 同时使用,xdebug 必须在 opcache 之后:
zend_extension=opcache
zend_extension=xdebug
[xdebug]
# xdebug.mode=off
xdebug.mode=develop,debug,trace
xdebug.client_host=127.0.0.1
# xdebug.client_host=192.168.66.254
xdebug.client_port=90742. redis 扩展
bash
cd /home/php-fpm/php_ext/redis-6.2.0
phpize
./configure --with-php-config=/server/php/84/bin/php-config
make -j4 > make.log
make test
make installbash
cd /home/php-fpm/php_ext/redis-6.2.0
/server/php/74/bin/phpize
./configure --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make test
make install3. MongoDB 扩展
bash
cd /home/php-fpm/php_ext/mongodb-2.0.0
phpize
./configure --with-php-config=/server/php/84/bin/php-config
make -j4 > make.log
make test
make installbash
cd /home/php-fpm/php_ext/mongodb-1.20.1
/server/php/74/bin/phpize
./configure --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make test
make install重要说明
- mongodb 扩展包
>1.20.1后的不再支持PHP 7.4 - 在 Debian12 发行版中
php-7.4.33在安装 mongodb 扩展时,必须使用跟编译 PHP 时兼容的 openssl 版本, 具体操作见[依赖 openssl 特殊版本]
4. yaml 扩展
bash
# 安装依赖库
apt install libyaml-dev -y
cd /home/php-fpm/php_ext/yaml-2.2.5
phpize
./configure --with-php-config=/server/php/84/bin/php-config
make -j4 > make.log
make test
make installbash
# 安装依赖库
apt install libyaml-dev -y
cd /home/php-fpm/php_ext/yaml-2.2.5
/server/php/74/bin/phpize
./configure --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make test
make install5. apcu 扩展
bash
cd /home/php-fpm/php_ext/apcu-5.1.27
phpize
./configure --with-php-config=/server/php/84/bin/php-config
make -j4 > make.log
make test
make installbash
cd /home/php-fpm/php_ext/apcu-5.1.27
/server/php/74/bin/phpize
./configure --with-php-config=/server/php/74/bin/php-config
make -j4 > make.log
make test
make install