35
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

phpでmecabを使う手順

Last updated at Posted at 2015-02-14

mecabをlinuxにインストール

sudo yum install gcc-c++
cd /tmp
wget https://mecab.googlecode.com/files/mecab-0.996.tar.gz
tar zxfv mecab-0.996.tar.gz
cd mecab-0.996
sudo ./configure --enable-utf8-only
sudo make
sudo make install

辞書のインストール

wget https://mecab.googlecode.com/files/mecab-ipadic-2.7.0-20070801.tar.gz
tar zxfv mecab-ipadic-2.7.0-20070801.tar.gz
cd mecab-ipadic-2.7.0-20070801
sudo ./configure --with-charset=utf8
sudo make
sudo make install

動作確認

mecab
すもももももももものうち

下記のようになっていればOK。

すもも  名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も      助詞,係助詞,*,*,*,*,も,モ,モ
もも    名詞,一般,*,*,*,*,もも,モモ,モモ
も      助詞,係助詞,*,*,*,*,も,モ,モ
もも    名詞,一般,*,*,*,*,もも,モモ,モモ
の      助詞,連体化,*,*,*,*,の,ノ,ノ
うち    名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ

phpにmecabモジュールを入れる

  • php-mecabのインストール
cd /tmp
wget https://github.com/rsky/php-mecab/archive/master.zip
unzip master.zip
cd php-mecab-master/mecab
phpize
sudo ./configure
sudo ./configure --with-php-config=/usr/bin/php-config --with-mecab=/usr/local/bin/mecab-config
sudo make
sudo make install
  • シンボリックリンクの作成
sudo ln -s /usr/lib64/php/modules/mecab.so /etc/php.d
  • php.iniの編集
vim /etc/php.ini
/etc/php.ini
 ;;;;;;;;;;;;;;;;;;;;;;
 ; Dynamic Extensions ;
 ;;;;;;;;;;;;;;;;;;;;;;

 ; If you wish to have an extension loaded automatically, use the following
 ; syntax:
 ;
 ;   extension=modulename.extension
 ;
 ; For example, on Windows:
 ;
 ;   extension=msql.dll
 ;
 ; ... or under UNIX:
 ;
 ;   extension=msql.so
 ;
 ; ... or with a path:
 ;
 ;   extension=/path/to/extension/msql.so
 ;
 ; If you only provide the name of the extension, PHP will look for it in its
 ; default extension directory.

 ;;;;
 ; Note: packaged extension modules are now loaded via the .ini files
 ; found in the directory /etc/php.d; these are loaded by default.
 ;;;;

 extension=mecab.so

  • apacheの再起動
service httpd restart
  • 動作確認

php -r 'phpinfo();' | grep 'mecab' -i 

以下のようになっていれば問題ない。

mecab
MeCab Support => enabled
MeCab Library => 0.996 => 0.996
mecab.default_dicdir => no value => no value
mecab.default_rcfile => no value => no value
mecab.default_userdic => no value => no value
35
36
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
35
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?