PHP:扩展/Intl

来自康健生活

返回上一级

Intl

源码安装

首先下载最新的 php intl 扩展源码。

wget http://pecl.php.net/get/intl-3.0.0.tgz
--2018-03-06 16:56:47--  http://pecl.php.net/get/intl-3.0.0.tgz
Resolving pecl.php.net (pecl.php.net)... 104.236.228.160
Connecting to pecl.php.net (pecl.php.net)|104.236.228.160|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 248200 (242K) [application/octet-stream]
Saving to: ‘intl-3.0.0.tgz’

intl-3.0.0.tgz                      100%[=================================================================>] 242.38K   148KB/s    in 1.6s    

2018-03-06 16:56:50 (148 KB/s) - ‘intl-3.0.0.tgz’ saved [248200/248200]

准备编译扩展的环境,这里需要注意的是,在执行phpize命令的时候,必须是在等待安装的php扩展程序文件夹里面执行。

tar -xzf intl-3.0.0.tgz && cd intl-3.0.0
/usr/bin/phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525

运行 ./configure 脚本来进行配置。

./configure --enable-intl --with-icu-dir=/usr/local/icu/ --with-php-config=/usr/local/php/bin/php-config
make && make install

安装完成后将extension=intl.so加入到php.ini文件中,然后执行重加载命令使php.ini配置生效。

/etc/init.d/php-fpm restart

查看intl扩展是否安装成功。

php -m | grep intl
intl

备注

在PHP7.0里,如果使用源码安装会出现兼容问题,具体体现为php_smart_str.h缺失(PHP7.0里为php_smart_string.h,并且两个文件差异略大),所以只能使用软件库安装。

find / -name php_smart_str.h

pecl安装

pecl install intl-3.0.0

安装过程中会让您指定ICU库的位置,我的位置是 /usr/local/icu。

icu安装

下载ICU源码文件。

wget http://download.icu-project.org/files/icu4c/60rc/icu4c-60rc-src.tgz
tar -zxvf icu4c-60rc-src.tgz && rm -rf icu4c-60rc-src.tgz && cd icu/source/

指定安装位置。

./configure --prefix=/usr/local/icu
make && make install

软件库安装

sudo apt-get install php7.0-intl