配置环境
Linux version 2.6.32-696.23.1.el6.x86_64
(mockbuild@x86-01.bsys.centos.org)
(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 解析域名到位
#防止编译过程失联
1 | screen -S soxiaohost |
#进入刚才新建虚拟主机的目录
1 | cd /home/wwwroot/so.xiaohost.com |
#下载scws
1 | wget http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2 |
#解压
1 | tar xvjf scws-1.2.3.tar.bz2 |
#进入目录
1 | cd scws-1.2.3 |
#编译
1 | ./configure --prefix=/usr/local/scws ; make ; make install |
#检查是否编译成功
1 | ls -al /usr/local/scws/lib/libscws.la |
#显示以下信息则成功
试试执行 scws-cli 文件
1 | /usr/local/scws/bin/scws -h |
正常应显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | scws (scws-cli/1.2.3) Simple Chinese Word Segmentation - Command line usage. Copyright (C)2007 by hightman. Usage: scws [options] [input] [output] -i <file|string> input string or filepath (default: try to read from <stdin> everyline) -o <file> output filepath (default to <stdout>) -c <charset> set the charset (default: gbk) charset must been same with dictionary & ruleset -r <file> set the ruleset file (default: none) -d <file> 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 <num> fetch the top words instead of segment -a [~]<attr1,attr2,...> 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 <hightman2@yahoo.com.cn> |
下载并解压词典,将 *.xdb 放入 /usr/local/scws/etc 目录中
1 | cd /usr/local/scws/etc |
GBK和UTF8的是两个字典文件
1 2 | 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扩展
扩展包更新包
1 | yum install epel-release -y |
更新yum源
1 | yum update -y |
安装必要的包
1 | yum install php-devel -y |
1 | yum install autoconf automake -y |
返回源码目录
1 | cd /home/wwwroot/so.xiaohost.com/scws-1.2.3/phpext |
执行phpize
1 | /usr/local/php/bin/phpize |
编译安装
1 | ./configure --with-scws=/usr/local/scws |
注意:若php安装在特殊目录$php_prefix,则请在configure后加上–with-php-config=$php_prefix/bin/php-config
执行 make 然后用 root 身份执行 make install
1 | make |
测试下是否编译成功
1 | make test |
编译安装
1 | make install |
正常情况下应该显示如下内容:
1 2 3 4 5 6 7 8 9 10 11 12 | ===================================================================== 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
1 | vi /usr/local/php/etc/php.ini |
配置内容:
1 2 3 4 5 6 7 8 | [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
1 | /etc/init.d/php-fpm restart |
命令行下执行 php -m 就能看到 scws 了或者在 phpinfo() 中看看关于 scws 的部分
补充:换了一个php版本后,重启时提示
1 | 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位的扩展
解决方法:在编译时加入
1 | ./configure --enable-64 --with-php-config=/usr/local/php/bin/php-config |
评论0