MENU

安装opencc和opencc4php成功了以后 无法启动的问题

May 6, 2019 • 已被 438 位童鞋围观过 • 代码分享,系统运维

opencc 和opencc4php 安装成功以后 重新PHP的时候 报错,

NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library 'opencc.so' (tried: /www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731/opencc.so (libopencc.so.2: cannot open shared object file: No such file or directory), /www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731/opencc.so.so (/www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731/opencc.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

查看 OpenCC 版本,报错

$ opencc --version
opencc: error while loading shared libraries: libopencc.so.2: cannot open shared object file: No such file or directory

解决办法如下

在系统中找到了相关文件

$ sudo find / -name libopencc.so.2
/usr/lib/libopencc.so.2

因为是64位系统,尝试在 lib64 目录下建立一个链接文件

$ sudo ln -s /usr/lib/libopencc.so.2 /usr/lib64/libopencc.so.2

再次查看 OpenCC 版本,没有报错了 重启PHP 也正常 OK!

$ opencc --version

Open Chinese Convert (OpenCC) Command Line Tool
Version: 1.0.3

测试使用:

$echo '嚴格區分「一簡對多繁」和「一簡對多異」' | opencc -c t2s
Last Modified: September 28, 2023