Linux系统安装SCWS-1.2.3及PHP扩展

来源:互联网 发布:闻道软件 编辑:程序博客网 时间:2024/06/11 15:30

取得 scws-1.2.3 的代码

wget http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2

解开压缩包

[hightman@d1 ~]$ tar xvjf scws-1.2.3.tar.bz2

进入目录执行配置脚本和编译

[hightman@d1 ~]$ cd scws-1.2.3[hightman@d1 ~/scws-1.2.3]$ ./configure --prefix=/usr/local/scws[hightman@d1 ~/scws-1.2.3]$ make[hightman@d1 ~/scws-1.2.3]$ make install

注:这里和通用的 GNU 软件安装方式一样,具体选项参数执行 ./configure –help 查看。
常用选项为:–prefix=

[hightman@d1 ~/scws-1.2.3]$ ls -al /usr/local/scws/lib/libscws.la

试试执行 scws-cli 文件

[hightman@d1 ~/scws-1.2.3]$ /usr/local/scws/bin/scws -hscws (scws-cli/1.2.3)Simple Chinese Word Segmentation - Command line usage.Copyright (C)2007 by hightman....

用 wget 下载并解压词典,或从主页下载然后自行解压再将 *.xdb 放入 /usr/local/scws/etc 目录中

[hightman@d1 ~/scws-1.2.3]$ cd /usr/local/scws/etc[hightman@d1 /usr/local/scws/etc]$ wget http://www.xunsearch.com/scws/down/scws-dict-chs-gbk.tar.bz2[hightman@d1 /usr/local/scws/etc]$ wget http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2[hightman@d1 /usr/local/scws/etc]$ wget http://www.xunsearch.com/scws/down/scws-dict-cht-utf8.tar.bz2[hightman@d1 /usr/local/scws/etc]$ tar xvjf scws-dict-chs-gbk.tar.bz2[hightman@d1 /usr/local/scws/etc]$ tar xvjf scws-dict-chs-utf8.tar.bz2[hightman@d1 /usr/local/scws/etc]$ tar xvjf scws-dict-cht-utf8.tar.bz2

写个小程序测试一下

[hightman@d1 ~]$ cat > test.c#include <scws.h>#include <stdio.h>main(){  scws_t s;  s = scws_new();  scws_free(s);  printf("test ok!\n");}

编译测试程序

[hightman@d1 ~]$ gcc -o test -I/usr/local/scws/include -L/usr/local/scws/lib test.c -lscws -Wl,--rpath -Wl,/usr/local/scws/lib[hightman@d1 ~]$ ./test

这样就好顺利安装完毕可以使用 libscws 这套 C-API 了

安装 php 扩展

假设您已经将 scws 按上述步骤安装到 /usr/local/scws 中。
安装此扩展要求您的 php 和系统环境安装了相应的 autoconf automake 工具及 phpize 。

  1. 进入源码目录的 phpext/ 目录 ( cd ~/scws-1.2.3 )
  2. 执行 phpize (在PHP安装目录的bin/目录下)
  3. 执行 ./configure --with-scws=/usr/local/scws 若 php 安装在特殊目录 $php_prefix, 则请在 configure 后加上 --with-php-config=$php_prefix/bin/php-config
  4. 执行 make 然后用 root 身份执行 make install
  5. 在 php.ini 中加入以下几行
    [scws]
    ;
    ; 注意请检查 php.ini 中的 extension_dir 的设定值是否正确, 否则请将 extension_dir 设为空,
    ; 再把 extension = scws.so 指定绝对路径。
    ;
    extension = scws.so
    scws.default.charset = utf8
    scws.default.fpath = /usr/local/scws/etc

  6. 重启php使新的 php.ini 生效。命令行下执行 php -m 就能看到 scws 了或者在 phpinfo() 中看看关于 scws 的部分。

  7. 如果重启php-fpm过程中出现错误信息
    NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '/opt/rh/php55/root/usr/lib64/php/modules/scws.so' - libscws.so.1: cannot open shared object file: No such file or directory in Unknown on line 0
    则需要建两个软连接:
    ln -s /usr/local/scws/lib/libscws.so.1.1.0 /usr/local/lib/libscws.so
    ln -s /usr/local/scws/lib/libscws.so.1.1.0 /usr/local/lib/libscws.so.1
  8. 这样就算安装完成了,余下的工作只是PHP代码编写问题了。
0 0
原创粉丝点击