使用源码编译安装PHP7.4是在各种Linux平台上安装PHP的主要形式,通常会遇到各种错误,不是缺少依赖,就是依赖的库版本太低。

主要问题

本人编译PHP碰到的错误主要有如下几个:

1)libxml的版本太低 

php7.4.1 configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:

2)libcurl的版本太低或缺少

3)openssl的版本太低或缺少

(openssl >= 1.0.1) were not met:

4)缺少sqlite3、oniguruma等库

No module named ‘_sqlite3′
No package ‘oniguruma‘ found

解决方法

1)如果依赖是必须使用的库,在CentOS等支持yum安装的系统中使用yum安装依赖,在ubuntu系统中apt-get安装依赖。

使用yum安装libcurl,openssl,libxml等依赖:

 yum install libxml2 libxml2-devel
 yum install openssl openssl-devel
 yum install curl curl-devel

2)如果不是必须的,则通过--without-xx 选型去掉这些依赖。

最终的configure命令:

./configure  --prefix=/usr/local/php  --enable-fpm  --with-pdo-mysql --with-mysqli --with-curl --enable-mbstring  --enable-bcmath  --with-openssl --enable-maintainer-zts --disable-mbregex --without-sqlite3 --without-pdo_sqlite

通过以上方法,configure会顺利通过,最后就是编译安装了

make
make install