龙空技术网

centos7.5编译安装php7.4.30踩坑记录

一起web编程 202

前言:

如今你们对“如何编译安装php”大概比较讲究,朋友们都需要分析一些“如何编译安装php”的相关知识。那么小编同时在网上收集了一些对于“如何编译安装php””的相关资讯,希望我们能喜欢,各位老铁们一起来了解一下吧!

因为等保安全要求,需要升级php的版本为php7.4.30. 原来的版本是7.2 ,目前爆出了不少的漏洞需要修复;唯一的办法就是升级版本。

为什么要升级到这个版本,因为这个版本是目前7.4的最后一个版本,目前发现的安全漏洞都已经进行了修复;

基本上软件版本都是这个规则,安装每个大版本的最后一个版本就对了;

下面是安装过程,记录这次安装的问题,以备后用。

环境:centos7.4 ,源码编译安装。

官网下载需要的源码

,下载需要的版本,上传到服务器,解压

2.编译

编译参数如下:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc  --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-fpm-user=www   --with-fpm-group=www --enable-fpm --enable-opcache --enable-mysqlnd    --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local   --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop   --enable-exif --enable-sysvsem --enable-inline-optimization    --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring    --with-password-argon2 --with-sodium=/usr/local --enable-gd --with-jpeg    --with-openssl=/usr/local/openssl --with-mhash --enable-pcntl    --enable-sockets --with-xmlrpc --enable-ftp --enable-intl    --with-xsl --with-gettext --enable-soap --disable-debug    --with-freetype=/usr/local/freetype   --with-zip --host=x86_64

每个人根据自己的需要做调整就好了,具体支持哪些参数,可通过./configure --help 查看,每个php的版本参数不完全一样。

3.make && make install

不出意外,这个过程肯定会出错,编译安装过软件的人都知道,下面是我遇到的问题:

1.configure: WARNING: unrecognized options: --with-jpeg-dir, --with-png-dir, --with-libxml-dir, --with-gd, --enable-zip, --with-freetype-dir

版本不同,支持的参数也不同,我用的是以前版本的参数,所以有些不支持,把不支持的去掉就ok了

2.configure: error: cannot run C compiled programs.

增加编译参数 --host=x86_64

3.error: Package requirements (libsodium >= 1.0.8) were not met

yum install libsodium-devel.x86_64 ,缺少类库是比较常见的错误,一般找到对应的包安装就可以了,记得一定是***-devel的包,因为编译需要的头文件在这里面;

4.make出错,

php-7.4.30/ext/iconv/iconv.c:2583: undefined reference to `libiconv_close'

ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor':

php-7.4.30/ext/iconv/iconv.c:2604: undefined reference to `libiconv_open'

解决方法:

修改 Makefile,找到EXTRA_LIBS=… 行末加上 –liconv,重新make

5.Requested 'libzip >= 0.11' but version of libzip is 0.10.1

使用yum安装的libzip版本是0.10 ,需要的最低版本是0.11 ,这也是一类常见的问题,需要自己下载源码安装,一般步骤如下

yum remove libzip libzip-devel -ywget  -zxvf libzip-1.2.0.tar.gzcd libzip-1.2.0./configuremake && make installexport PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"

安装完成后,还要检查自己的程序、使用的框架是否有兼容的地方,就像我用的thinkphp5.0 ,升级版本就有出错

 Array and string offset access syntax with curly braces is deprecated[/data/wwwroot/dq.admin.shenzhenshizhi.cn/thinkphp/library/think/db/Query.php:400

原因:从7.4以后,只能使用第一种形式$value[0]获取字符串偏移了,第二种方法$value{0}被弃用。

最后总结一下:很多人怕自己编译安装软件,因为需要解决很多软件依赖,有些类库找不到,其实遇到问题不要怕,很多问题别人都遇到过,而且有解决办法,只要不断查资料,找办法,不断测试,总结经验,慢慢就会越来越熟练。

标签: #如何编译安装php