PHP8.0.X发布有一段时间了,但是各个PHP的扩展却跟不上步伐。
刚开始体验php8.0.X的时候想着没有扩展就自己动手装,能有多难呢?但是现实总是很残酷。
编译php的时候开启fileinfo扩展的时候一直提示安装失败,想着fileinfo编译会占用大量系统资源,可能是我的机器内存太小了,给了Swap分区依然失败,最后手工进行编译安装,依然失败,狠狠的打脸了。

然后我手工编译

继续失败,然后分析一下错误提示,use option -std=c99 or -std=gnu99
难道是makefile文件有错误,是fileinfo并不支持php8.0.X版本,我一脸问题,不支持你放在安装包里干什么?
分析了一下makefile文件,然后疯狂搜索解决办法,终于是找到的解决办法,现在分享出来给需要的朋友。

在第25行里加入 -std=c99 效果如下:

竟然编译通过了,并且安装成功了!

具体操作如下:
使用操作系统:Centos 7.9,搭配环境:oneinstack 一键包为例,其它也应该是同样的方法。
下面是安装过程:
进入fileinfo扩展目录
cd /root/oneinstack/src/php-8.0.3/ext/fileinfo
对编译进行清理
make clean
正常编译安装
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
到这一步,fileinfo文件夹下应该生成了makefile文件,对makefile文件进行修改,
第25行
CFLAGS = -g -02 修改为 CFLAGS = -std=c99 -g -02 如下:

修改后保存文件
然后进行make && makeinstall
make && makeinstall
然后就顺利编译成功了!

最后查看一下有没有fileinfo.so文件。
然后加入到php.ini文件中,在oneinstack中是直接做fileinfo.ini文件
echo 'extension=fileinfo.so' > /usr/local/php/etc/php.d/ext-fileinfo.ini
然后重启php或是nginx或apache等,我这边php是以php-fpm方式运行,所以重启php就行了。
service php-fpm restart
php -m检查扩展,或是使用phpinfo查看,我这安装了探针。

已经安装完成了。
微信扫描下方的二维码阅读本文
我的是php8.1 ,我的修改方法是CFLAGS = -g -02 修改为 CFLAGS = -std=c99,后面的-g -02 不能要,否则失败
我还没有试过8.1,但是8以上版本安装这个有点难