4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

php-mecabインストール

Last updated at Posted at 2018-06-26

mecabインストール

# tar xvzf mecab-0.996.tar.gz
# cd mecab-0.996
# ./configure --enable-utf8-only --enable-mutex 
### エラーが出る場合は ./configure --with-charset=utf8 --enable-utf8-only のオプションに変更
# make
# make check
# make install

# tar xvzf mecab-ipadic-2.7.0-20070801.tar.gz
# cd mecab-ipadic-2.7.0-20070801
# ./configure --with-charset=utf8
# make
# make install

PHP7向け

# git clone https://github.com/rsky/php-mecab 
# cd php-mecab/mecab 
# phpize
# ./configure --with-mecab=/usr/local/bin/mecab-config 
# make
# make install

# vi /etc/php.ini
「extension=mecab.so」を追記

PHP8 向け

# git clone https://github.com/ranvis/php-mecab.git
# cd php-mecab/mecab 
# phpize
# ./configure --with-mecab=/usr/local/bin/mecab-config 
# make
# make install

# vi /etc/php.ini
「extension=mecab.so」を追記

使用例

$str = "すもももももももものうち";
$t = new \MeCab\Tagger();
$m = explode("\n", $t->parse($str));

エラーが出る場合

# make
/bin/sh /usr/local/src/php-mecab/mecab/libtool --mode=link cc -DPHP_ATOM_INC -I/usr/local/src/php-mecab/mecab/include -I/usr/local/src/php-mecab/mecab/main -I/usr/local/src/php-mecab/mecab -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2  -L/usr/lib64 -o mecab.la -export-dynamic -avoid-version -prefer-pic -module -rpath /usr/local/src/php-mecab/mecab/modules  mecab7.lo -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lmecab -lstdc++
libtool: link: cc -shared  .libs/mecab7.o   -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib/../lib -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib/../lib -L/usr/lib64 -L/usr/local/lib /usr/local/lib/libmecab.so -lpthread /usr/local/lib/../lib/libstdc++.so -lm  -Wl,-rpath -Wl,/usr/local/lib   -Wl,-soname -Wl,mecab.so -o .libs/mecab.so
/usr/local/lib/../lib/libstdc++.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status

configure のオプションを指定

# LDFLAGS=-L/usr/local/lib64 ./configure
# make
# make install

/etc/ld.so.conf 見てくれない時などは上記のオプションが便利
インストール後に mecab.so ができていることを確認する

# make install
Installing shared extensions:     /usr/lib64/php/modules/
# ls /usr/lib64/php/modules/
bz2.so       exif.so      gmp.so       mecab.so    pdo_mysql.so   simplexml.so  sysvsem.so    xdebug.so
calendar.so  fileinfo.so  iconv.so     mysqli.so   pdo_sqlite.so  soap.so       sysvshm.so    xml.so
ctype.so     ftp.so       json.so      mysqlnd.so  phar.so        sockets.so    tidy.so       xmlreader.so
curl.so      gd.so        mbstring.so  opcache.so  posix.so       sqlite3.so    tokenizer.so  xmlwriter.so
dom.so       gettext.so   mcrypt.so    pdo.so      shmop.so       sysvmsg.so    wddx.so       xsl.so
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?