PHP compile and install fileinfo extension

Preface

According to the manual, the fileinfo extension is enabled by default after php5.3, so we don't need to install it separately. However, some integrated environments remove the installation of this extension in order to increase the speed or save resources when compiling php. So we need to install it ourselves.

step

1. We install this extension from the source code of fileinfo. The source code of fileinfo is under the "/mnt/php-7.4.14/ext/fileinfo" directory of the php source code, you can use find to find the specific path

[root@VM-0-6-centos ~]# find / -name fileinfo
/mnt/php-7.4.14/ext/fileinfo

In the case that the source code does not exist, check the current version through php -v to the php official website to pull the corresponding source code version and repeat the previous step.

[root@VM-0-6-centos ~]# php -v
PHP 7.4.14 (cli) (built: Jan  9 2021 22:22:44) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

2. Start the installation of the extension:

1)进入fileinfo目录
cd /mnt/php-7.4.14/ext/fileinfo
2)编译与安装fileinfo
/usr/local/php/bin/phpize

/configure --with-php-config=/usr/local/php/bin/php-config

make && make install
3)给php支持打fileinfo模块,vim /usr/local/php/etc/php.ini 添加
extension=fileinfo.so 

View fileinfo extension

1. Command method:

/usr/local/php/bin/php -m | grep fileinfo

2. Intuitive phpinfo way:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_39218464/article/details/114056872