php安装fileinfo扩展

环境:CentOS+nginx+php7.0

1、下载扩展包,根据自己php版本下载不同版本的安装包

wget -O php-5.6.25.tar.gz http://cn2.php.net/get/php-7.0.30.tar.gz/from/this/mirror

2、解压

tar -zxvf php-7.0.30.tar.gz

3、进入扩展目录

cd php-7.0.30/ext/fileinfo/

4、执行phpize

/usr/local/php/bin/phpize

5、在扩展目录执行编译配置

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

6、编译安装

make && make install

安装完成后可以查看/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/目录下应该有fileinfo.so文件

7、修改php.ini开启fileinfo扩展

vi /usr/local/php/etc/php.ini

找到;extension=…配置区域

添加一行:

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

保存后重启php:

service php-fpm restart

如果报如下错误:

Gracefully shutting down php-fpm . done
Starting php-fpm [06-Sep-2018 12:24:13] NOTICE: PHP message: PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) ‘/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/fileinfo.so’ in Unknown on line 0
done

则需要重新进入扩展包目录,先执行如下命令:

make clean

然后再重新执行4~7步骤。

8、查看phpinfo里面会有fileinfo扩展相关参数

 

CI框架在nginx下的伪静态规则配置

CI框架在NGINX下的伪静态规则修改:

1、location

location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}

2、location ~ [^/]\.php(/|$)

location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;

#增加以下两行
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;

include fastcgi.conf;
}