配置环境
Linux version 2.6.32-696.23.1.el6.x86_64
(gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) )
CentOS release 6.9 64bit (Final)
nginx version: nginx/1.12.2
PHP 5.3.3
Zend Engine v2.3.0
Mysql Server version: 5.5.56
#1 安装scws中文分词系统
#ssh连接上服务器(已配置lnmp)
#新建一个虚拟主机so.xiaohost.com 解析域名到位
#防止编译过程失联
screen -S soxiaohost
#进入刚才新建虚拟主机的目录
cd /home/wwwroot/so.xiaohost.com
#下载scws
wget http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2
#解压
tar xvjf scws-1.2.3.tar.bz2
#进入目录
cd scws-1.2.3
#编译
./configure --prefix=/usr/local/scws ; make ; make install
#检查是否编译成功
ls -al /usr/local/scws/lib/libscws.la
#显示以下信息则成功
试试执行 scws-cli 文件
/usr/local/scws/bin/scws -h
正常应显示
scws (scws-cli/1.2.3)
Simple Chinese Word Segmentation - Command line usage.
Copyright (C)2007 by hightman.
Usage: scws [options] [input] [output]
-i input string or filepath
(default: try to read from everyline)
-o output filepath (default to )
-c set the charset (default: gbk)
charset must been same with dictionary & ruleset
-r set the ruleset file (default: none)
-d set the dictionary file[s] (default: none)
if there are multi files, split filepath use ':'
if the file suffix is .txt, it will be treated as plain text dict.
-M <1~15> use multi child words mode(中国人->中国+人+中国人)
1|2|4|8: short|duality|zmain|zall
-I ignore the all mark symbol such as ,:
-A show the word attribute
-E import the xdb dict into xtree(memory)
-N don't show time usage and warnings
-D debug segment, see the segment detail
-U use duality algorithm for single chinese
-t fetch the top words instead of segment
-a [~] prefix by ~ means exclude them.
For topwords, exclude or include some word attrs
-v Show the version.
-h Show this page for help.
Report bugs to
下载并解压词典,将 *.xdb 放入 /usr/local/scws/etc 目录中
cd /usr/local/scws/etc
GBK和UTF8的是两个字典文件
wget http://www.xunsearch.com/scws/down/scws-dict-chs-gbk.tar.bz2 && tar xvjf scws-dict-chs-gbk.tar.bz2
wget http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2 && tar xvjf scws-dict-chs-utf8.tar.bz2
安装php扩展
扩展包更新包
yum install epel-release -y
更新yum源
yum update -y
安装必要的包
yum install php-devel -y
yum install autoconf automake -y
返回源码目录
cd /home/wwwroot/so.xiaohost.com/scws-1.2.3/phpext
执行phpize
/usr/local/php/bin/phpize
编译安装
./configure --with-scws=/usr/local/scws
注意:若php安装在特殊目录$php_prefix,则请在configure后加上--with-php-config=$php_prefix/bin/php-config
执行 make 然后用 root 身份执行 make install
make
测试下是否编译成功
make test
编译安装
make install
正常情况下应该显示如下内容:
=====================================================================
PHP : /usr/bin/php
PHP_SAPI : cli
PHP_VERSION : 5.3.3
ZEND_VERSION: 2.3.0
PHP_OS : Linux - Linux 2.xiaohost.com 2.6.32-696.23.1.el6.x86_64 #1 SMP Tue Mar 13 22:44:18 UTC 2018 x86_64
INI actual : /home/wwwroot/so.xiaohost.com/scws-1.2.3/phpext/tmp-php.ini
More .INIs :
CWD : /home/wwwroot/so.xiaohost.com/scws-1.2.3/phpext
Extra dirs :
VALGRIND : Not used
=====================================================================
在 php.ini 中加入配置,按shift + G 跳到最后一行,insert
vi /usr/local/php/etc/php.ini
配置内容:
[scws]
;
; 注意请检查 php.ini 中的 extension_dir 的设定值是否正确, 否则请将 extension_dir 设为空,
; 再把 extension = scws.so 指定绝对路径。
;
extension = /usr/lib64/php/modules/scws.so
scws.default.charset = utf-8
scws.default.fpath = /usr/local/scws/etc
wq保存,退出vim,重启php-fpm
/etc/init.d/php-fpm restart
命令行下执行 php -m 就能看到 scws 了或者在 phpinfo() 中看看关于 scws 的部分
补充:换了一个php版本后,重启时提示
Starting php-fpm [16-Mar-2018 09:39:01] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/scws.so' - /usr/lib64/php/modules/scws.so: undefined symbol: zend_new_interned_string in Unknown on line 0
原因是php为32位,不支持加载64位的扩展
解决方法:在编译时加入
./configure --enable-64 --with-php-config=/usr/local/php/bin/php-config