给php-7-1-5添加扩展fileinfo

fileinfo 这个扩展是 php 自带的,但是使用 lnmp 一键安装脚本部署的时候并没有启用这个扩展,今天想要部署一个图床服务需要安装这个扩展。

在网上看了不少的文章,基本上都没有效果。这里记录下。

先来看一下是什么状态:

[root@eryajf ~]$php -i |grep fileinfo
Configure Command =>  './configure'  '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-config-file-scan-dir=/usr/local/php/conf.d' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--enable-mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--enable-intl' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo' '--enable-opcache' '--with-xsl'
fileinfo
fileinfo support => enabled

然后去到源码目录进行重新编译添加:

[root@eryajf ~]$cd /mnt/lnmp1.4-full/src/php-7.1.5/ext/fileinfo/

这时这个目录是无法直接编译的,需要执行以下命令生成编译文件:

[root@eryajf fileinfo]$phpize
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303

然后进行编译即可:

./configure --with-php-config=/usr/local/php/bin/php-config --enable-fileinfo
make && make install

如果执行无误,则会在最后输出一个目录。

[root@eryajf min-wiki]$ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303
fileinfo.so  opcache.a  opcache.so

可以看到这里已经生成了需要的 so 文件。

接着配置php.ini进行引用:

extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/fileinfo.so"

将如上内容添加在文件当中。然后重启即可。
不过在重启的时候可能会遇到下边的报错:

NOTICE: PHP message: PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) ‘fileinfo.so’ in Unknown on line 0

解决办法是回到上边添加一条命令:

$ rm -rf /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/fileinfo.so
$ make clean
$ ./configure --with-php-config=/usr/local/php/bin/php-config --enable-fileinfo
$ make && make install

然后再重启就能够看到添加成功了。

[root@eryajf fileinfo]$php -m |grep fileinfo
fileinfo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CN-FuWei

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值