前言:
第一篇文章讲完了Linux环境下安装scws分词工具php插件的前期工作,接下来我们将开始正式用phpize编译安装Php的SCWS插件了!!
用phpize编译安装Php的SCWS插件
如果上述环境都没有任何问题,那么接下来你可以正式开始你的SCWS分词工具安装了:
-
- 进入scws-1.2.3安装源码的目录 phpext/
cd ~/scws-1.2.3/phpext/
-
- 在/phpext/目录中执行PHP安装目录下的bin目录下的phpize
安装命令如下(Php5.5):
# /opt/remi/php55/root/bin/phpize
Php7.0的安装方式就用如下命令:
# /opt/remi/php70/root/bin/phpize
返回如下:
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212 - 在/phpext/目录中执行PHP安装目录下的bin目录下的phpize
如果你是Php7.0的话用就用如下命令:
# /opt/remi/php70/root/bin/phpize
返回如下:
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
- 就在上面的当前目录执行
# ./configure --with-scws=/usr/local/scws
结果有提示如下错误:
configure: error: Cannot find php-config. Please use --with-php-config=PAT
看来我们需要指定文件php-config的具体位置了,改成如下的形式:
命令如下(Php5.5):
# ./configure --with-scws=/usr/local/scws--with-php-config=/opt/remi/php55/root/bin/php-config
如果你是Php7.0的话用就用如下命令:
# ./configure --with-scws=/usr/local/scws --with-php-config=/opt/remi/php70/root/bin/php-config
返回了一堆的信息,那么恭喜你,估计你应该离成功不远了。
-
执行
make
返回如下信息:Libraries have been installed in:
/root/scsws-1.2.3/phpext/modulesIf you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the
LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to theLD_RUN_PATH' environment variable during linking - use the
-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
Build complete.
Don't forget to run 'make test'. 然后用 root 身份执行
make install
返回如下信息的话证明SCWS分词插件安装成功!
PHP5.5环境返回信息
Installing shared extensions: /opt/remi/php55/root/usr/lib64/php/modules/
PHP7.0环境返回信息
Installing shared extensions: /opt/remi/php70/root/usr/lib64/php/modules/
- 最后一步是在 php.ini 文件中加入以下几行
PHP5.5的路径
/opt/remi/php55/root/etc/php.ini
PHP7.0的路径跟Php5.5的路径略有不同
/etc/opt/remi/php70/php.ini
[scws]
;
; 注意请检查 php.ini 中的 extension_dir 的设定值是否正确, 否则请将 extension_dir 设为空,
; 再把 extension = scws.so 指定绝对路径。
;
extension = scws.so
scws.default.charset = gbk
scws.default.fpath = /usr/local/scws/etc
注:上文的
scws.default.charset = gbk
可按你的需要改为scws.default.charset = UTF-8
设定完毕保存,再重启php服务
# systemctl restart php55-php-fpm.service
才能使新的 php.ini 生效,查看phpinfo信息如下图:
测试分词效果:
Linux系的服务器测试代码test.php如下
<?php
$msg = '大家好,我的名字叫李白,很高兴认识大家!';
$shfc = scws_open();
scws_set_dict($shfc, '/usr/local/scws/etc/dict.utf8.xdb');
scws_set_rule($shfc, '/usr/local/scws/etc/rules.utf8.ini');
scws_set_ignore($shfc,true);
scws_send_text($shfc, $msg);
$Amsg2 = scws_get_result($shfc);
scws_close($shfc);
foreach($Amsg2 as $value)
{
foreach($value as $key => $value2)
{
echo $value2 .',';
}
echo '<br />';
}
?>
如果是windows系的服务器的话,只需要把上面的词库地址的参数更改为相应的地址就行。
scws_set_dict($shfc, ini_get("scws.default.fpath").'\dict.utf8.xdb', SCWS_XDICT_XDB);
或者是
scws_set_dict($shfc,'c:\program Files\scws\dict.utf8.xdb', SCWS_XDICT_XDB);
运行结果见下图。
至此SCWS已成功安装完毕,接下来的使用就不在本文的讨论范围了,下面主要说一下SCWS-1.2.3的自定义词库,另外开篇吧!
Tag:Php分词, SCWS, 分词技术
发布时间:2015年10月22日
博客被黑,挪窝简书安家……