LoginSignup
16
15

More than 5 years have passed since last update.

yumとPEARのみでPHPからMeCabを使って形態素解析ができる環境を構築

Last updated at Posted at 2016-02-14

[前提]
MeCabをyumでインストール完了 している
[目的]
yumとPEARを使い、PHPからMeCabを使えるようにopendogsのmecab-betaをインストールする

PEARのインストール

PEARを使ってライブラリをインストールできるよう、PEARを準備します。

PEARインストール
sudo yum install php-pear
読み込んだプラグイン:fastestmirror, remove-with-leaves, show-leaves
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ php-pear.noarch 1:1.9.4-21.el7 を インストール
--> 依存性の処理をしています: php-zlib のパッケージ: 1:php-pear-1.9.4-21.el7.noarch
--> 依存性の処理をしています: php-xml のパッケージ: 1:php-pear-1.9.4-21.el7.noarch
--> 依存性の処理をしています: php-tokenizer のパッケージ: 1:php-pear-1.9.4-21.el7.noarch
--> 依存性の処理をしています: php-posix のパッケージ: 1:php-pear-1.9.4-21.el7.noarch
--> 依存性の処理をしています: php-pcre のパッケージ: 1:php-pear-1.9.4-21.el7.noarch
--> 依存性の処理をしています: php-ftp のパッケージ: 1:php-pear-1.9.4-21.el7.noarch
--> 依存性の処理をしています: php-cli のパッケージ: 1:php-pear-1.9.4-21.el7.noarch
--> 依存性の処理をしています: php-bz2 のパッケージ: 1:php-pear-1.9.4-21.el7.noarch
--> トランザクションの確認を実行しています。
---> パッケージ php-cli.x86_64 0:5.4.16-36.el7_1 を インストール
---> パッケージ php-common.x86_64 0:5.4.16-36.el7_1 を インストール
--> 依存性の処理をしています: libzip.so.2()(64bit) のパッケージ: php-common-5.4.16-36.el7_1.x86_64
---> パッケージ php-process.x86_64 0:5.4.16-36.el7_1 を インストール
---> パッケージ php-xml.x86_64 0:5.4.16-36.el7_1 を インストール
--> 依存性の処理をしています: libxslt.so.1(LIBXML2_1.0.24)(64bit) のパッケージ: php-xml-5.4.16-36.el7_1.x86_64
--> 依存性の処理をしています: libxslt.so.1(LIBXML2_1.0.22)(64bit) のパッケージ: php-xml-5.4.16-36.el7_1.x86_64
--> 依存性の処理をしています: libxslt.so.1(LIBXML2_1.0.18)(64bit) のパッケージ: php-xml-5.4.16-36.el7_1.x86_64
--> 依存性の処理をしています: libxslt.so.1(LIBXML2_1.0.13)(64bit) のパッケージ: php-xml-5.4.16-36.el7_1.x86_64
--> 依存性の処理をしています: libxslt.so.1(LIBXML2_1.0.11)(64bit) のパッケージ: php-xml-5.4.16-36.el7_1.x86_64
--> 依存性の処理をしています: libxslt.so.1()(64bit) のパッケージ: php-xml-5.4.16-36.el7_1.x86_64
--> 依存性の処理をしています: libexslt.so.0()(64bit) のパッケージ: php-xml-5.4.16-36.el7_1.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ libxslt.x86_64 0:1.1.28-5.el7 を インストール
---> パッケージ libzip.x86_64 0:0.10.1-8.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===========================================================================================================================================
 Package                            アーキテクチャー              バージョン                             リポジトリー                 容量
===========================================================================================================================================
インストール中:
 php-pear                           noarch                        1:1.9.4-21.el7                         base                        357 k
依存性関連でのインストールをします:
 libxslt                            x86_64                        1.1.28-5.el7                           base                        242 k
 libzip                             x86_64                        0.10.1-8.el7                           base                         48 k
 php-cli                            x86_64                        5.4.16-36.el7_1                        base                        2.7 M
 php-common                         x86_64                        5.4.16-36.el7_1                        base                        563 k
 php-process                        x86_64                        5.4.16-36.el7_1                        base                         54 k
 php-xml                            x86_64                        5.4.16-36.el7_1                        base                        124 k

トランザクションの要約
===========================================================================================================================================
インストール  1 パッケージ (+6 個の依存関係のパッケージ)

総ダウンロード容量: 4.1 M
インストール容量: 16 M
Is this ok [y/d/N]: y
Downloading packages:
(1/7): libxslt-1.1.28-5.el7.x86_64.rpm                                                                              | 242 kB  00:00:00     
(2/7): libzip-0.10.1-8.el7.x86_64.rpm                                                                               |  48 kB  00:00:00     
(3/7): php-common-5.4.16-36.el7_1.x86_64.rpm                                                                        | 563 kB  00:00:00     
(4/7): php-pear-1.9.4-21.el7.noarch.rpm                                                                             | 357 kB  00:00:00     
(5/7): php-process-5.4.16-36.el7_1.x86_64.rpm                                                                       |  54 kB  00:00:00     
(6/7): php-cli-5.4.16-36.el7_1.x86_64.rpm                                                                           | 2.7 MB  00:00:00     
(7/7): php-xml-5.4.16-36.el7_1.x86_64.rpm                                                                           | 124 kB  00:00:00     
-------------------------------------------------------------------------------------------------------------------------------------------
合計                                                                                                        12 MB/s | 4.1 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : libzip-0.10.1-8.el7.x86_64                                                                                 1/7 
  インストール中          : php-common-5.4.16-36.el7_1.x86_64                                                                          2/7 
  インストール中          : php-process-5.4.16-36.el7_1.x86_64                                                                         3/7 
  インストール中          : php-cli-5.4.16-36.el7_1.x86_64                                                                             4/7 
  インストール中          : libxslt-1.1.28-5.el7.x86_64                                                                                5/7 
  インストール中          : php-xml-5.4.16-36.el7_1.x86_64                                                                             6/7 
  インストール中          : 1:php-pear-1.9.4-21.el7.noarch                                                                             7/7 
  検証中                  : php-process-5.4.16-36.el7_1.x86_64                                                                         1/7 
  検証中                  : php-cli-5.4.16-36.el7_1.x86_64                                                                             2/7 
  検証中                  : libxslt-1.1.28-5.el7.x86_64                                                                                3/7 
  検証中                  : libzip-0.10.1-8.el7.x86_64                                                                                 4/7 
  検証中                  : php-xml-5.4.16-36.el7_1.x86_64                                                                             5/7 
  検証中                  : php-common-5.4.16-36.el7_1.x86_64                                                                          6/7 
  検証中                  : 1:php-pear-1.9.4-21.el7.noarch                                                                             7/7 

インストール:
  php-pear.noarch 1:1.9.4-21.el7                                                                                                           

依存性関連をインストールしました:
  libxslt.x86_64 0:1.1.28-5.el7                 libzip.x86_64 0:0.10.1-8.el7                   php-cli.x86_64 0:5.4.16-36.el7_1          
  php-common.x86_64 0:5.4.16-36.el7_1           php-process.x86_64 0:5.4.16-36.el7_1           php-xml.x86_64 0:5.4.16-36.el7_1          

完了しました!
New leaves:
  php-pear.noarch

PEARのチャネル登録

OpenDogs PHP extension channel をPEARのチャネルに追加します。

PEARのチャネル追加
sudo pear channel-discover pecl.opendogs.org
Adding Channel "pecl.opendogs.org" succeeded
Discovery of channel "pecl.opendogs.org" succeeded
このチャネルからインストール可能なパッケージを確認
sudo pear remote-list -c opendogs
Channel opendogs Available packages:
====================================
Package      Version
gdextra      -n/a-
mecab        -n/a-
qr           -n/a-
tokyocabinet -n/a-
unichar      -n/a-

opendogs/mecab-betaに必要なパッケージのインストール

php-develのインストール

php-develが無いと、sudo pear install opendogs/mecab-beta をした場合、以下のようなエラーが発生します。

downloading mecab-0.6.0.tgz ...
Starting to download mecab-0.6.0.tgz (50,194 bytes)
.............done: 50,194 bytes
8 source files, building
running: phpize
Can't find PHP headers in /usr/include/php
The php-devel package is required for use of this command.
ERROR: `phpize' failed

そのため、あらかじめphp-develをインストールします。

php-develのインストール
sudo yum install php-devel
読み込んだプラグイン:fastestmirror, remove-with-leaves, show-leaves
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ php-devel.x86_64 0:5.4.16-36.el7_1 を インストール
--> 依存性の処理をしています: pcre-devel(x86-64) のパッケージ: php-devel-5.4.16-36.el7_1.x86_64
--> 依存性の処理をしています: automake のパッケージ: php-devel-5.4.16-36.el7_1.x86_64
--> 依存性の処理をしています: autoconf のパッケージ: php-devel-5.4.16-36.el7_1.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ autoconf.noarch 0:2.69-11.el7 を インストール
--> 依存性の処理をしています: perl(Data::Dumper) のパッケージ: autoconf-2.69-11.el7.noarch
---> パッケージ automake.noarch 0:1.13.4-3.el7 を インストール
--> 依存性の処理をしています: perl(Thread::Queue) のパッケージ: automake-1.13.4-3.el7.noarch
--> 依存性の処理をしています: perl(TAP::Parser) のパッケージ: automake-1.13.4-3.el7.noarch
---> パッケージ pcre-devel.x86_64 0:8.32-15.el7 を インストール
--> トランザクションの確認を実行しています。
---> パッケージ perl-Data-Dumper.x86_64 0:2.145-3.el7 を インストール
---> パッケージ perl-Test-Harness.noarch 0:3.28-3.el7 を インストール
---> パッケージ perl-Thread-Queue.noarch 0:3.02-2.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===========================================================================================================================================
 Package                                アーキテクチャー            バージョン                             リポジトリー               容量
===========================================================================================================================================
インストール中:
 php-devel                              x86_64                      5.4.16-36.el7_1                        base                      600 k
依存性関連でのインストールをします:
 autoconf                               noarch                      2.69-11.el7                            base                      701 k
 automake                               noarch                      1.13.4-3.el7                           base                      679 k
 pcre-devel                             x86_64                      8.32-15.el7                            base                      478 k
 perl-Data-Dumper                       x86_64                      2.145-3.el7                            base                       47 k
 perl-Test-Harness                      noarch                      3.28-3.el7                             base                      302 k
 perl-Thread-Queue                      noarch                      3.02-2.el7                             base                       17 k

トランザクションの要約
===========================================================================================================================================
インストール  1 パッケージ (+6 個の依存関係のパッケージ)

総ダウンロード容量: 2.8 M
インストール容量: 10 M
Is this ok [y/d/N]: y
Downloading packages:
(1/7): autoconf-2.69-11.el7.noarch.rpm                                                                              | 701 kB  00:00:00     
(2/7): automake-1.13.4-3.el7.noarch.rpm                                                                             | 679 kB  00:00:00     
(3/7): perl-Data-Dumper-2.145-3.el7.x86_64.rpm                                                                      |  47 kB  00:00:00     
(4/7): pcre-devel-8.32-15.el7.x86_64.rpm                                                                            | 478 kB  00:00:00     
(5/7): perl-Test-Harness-3.28-3.el7.noarch.rpm                                                                      | 302 kB  00:00:00     
(6/7): perl-Thread-Queue-3.02-2.el7.noarch.rpm                                                                      |  17 kB  00:00:00     
(7/7): php-devel-5.4.16-36.el7_1.x86_64.rpm                                                                         | 600 kB  00:00:00     
-------------------------------------------------------------------------------------------------------------------------------------------
合計                                                                                                       8.4 MB/s | 2.8 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : perl-Test-Harness-3.28-3.el7.noarch                                                                        1/7 
  インストール中          : pcre-devel-8.32-15.el7.x86_64                                                                              2/7 
  インストール中          : perl-Thread-Queue-3.02-2.el7.noarch                                                                        3/7 
  インストール中          : perl-Data-Dumper-2.145-3.el7.x86_64                                                                        4/7 
  インストール中          : autoconf-2.69-11.el7.noarch                                                                                5/7 
  インストール中          : automake-1.13.4-3.el7.noarch                                                                               6/7 
  インストール中          : php-devel-5.4.16-36.el7_1.x86_64                                                                           7/7 
  検証中                  : autoconf-2.69-11.el7.noarch                                                                                1/7 
  検証中                  : perl-Data-Dumper-2.145-3.el7.x86_64                                                                        2/7 
  検証中                  : php-devel-5.4.16-36.el7_1.x86_64                                                                           3/7 
  検証中                  : perl-Thread-Queue-3.02-2.el7.noarch                                                                        4/7 
  検証中                  : pcre-devel-8.32-15.el7.x86_64                                                                              5/7 
  検証中                  : automake-1.13.4-3.el7.noarch                                                                               6/7 
  検証中                  : perl-Test-Harness-3.28-3.el7.noarch                                                                        7/7 

インストール:
  php-devel.x86_64 0:5.4.16-36.el7_1                                                                                                       

依存性関連をインストールしました:
  autoconf.noarch 0:2.69-11.el7                 automake.noarch 0:1.13.4-3.el7                pcre-devel.x86_64 0:8.32-15.el7              
  perl-Data-Dumper.x86_64 0:2.145-3.el7         perl-Test-Harness.noarch 0:3.28-3.el7         perl-Thread-Queue.noarch 0:3.02-2.el7        

完了しました!
New leaves:
  php-devel.x86_64

gccのインストール

まだ、この状態でも、sudo pear install opendogs/mecab-beta をすると以下のようにエラーになります。

downloading mecab-0.6.0.tgz ...
Starting to download mecab-0.6.0.tgz (50,194 bytes)
.............done: 50,194 bytes
8 source files, building
running: phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
specify pathname to mecab-config [no] : /usr/bin/mecab-config
building in /var/tmp/pear-build-rootkF6FiR/mecab-0.6.0
running: /var/tmp/mecab/configure --with-mecab=/usr/bin/mecab-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... no
checking for gcc... no
configure: error: in `/var/tmp/pear-build-rootkF6FiR/mecab-0.6.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
ERROR: `/var/tmp/mecab/configure --with-mecab=/usr/bin/mecab-config' failed

そのため、gccをインストールします。

gccのインストール
sudo yum install gcc
読み込んだプラグイン:fastestmirror, remove-with-leaves, show-leaves
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ gcc.x86_64 0:4.8.5-4.el7 を インストール
--> 依存性の処理をしています: cpp = 4.8.5-4.el7 のパッケージ: gcc-4.8.5-4.el7.x86_64
--> 依存性の処理をしています: glibc-devel >= 2.2.90-12 のパッケージ: gcc-4.8.5-4.el7.x86_64
--> 依存性の処理をしています: libmpfr.so.4()(64bit) のパッケージ: gcc-4.8.5-4.el7.x86_64
--> 依存性の処理をしています: libmpc.so.3()(64bit) のパッケージ: gcc-4.8.5-4.el7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ cpp.x86_64 0:4.8.5-4.el7 を インストール
---> パッケージ glibc-devel.x86_64 0:2.17-106.el7_2.1 を インストール
--> 依存性の処理をしています: glibc-headers = 2.17-106.el7_2.1 のパッケージ: glibc-devel-2.17-106.el7_2.1.x86_64
--> 依存性の処理をしています: glibc-headers のパッケージ: glibc-devel-2.17-106.el7_2.1.x86_64
---> パッケージ libmpc.x86_64 0:1.0.1-3.el7 を インストール
---> パッケージ mpfr.x86_64 0:3.1.1-4.el7 を インストール
--> トランザクションの確認を実行しています。
---> パッケージ glibc-headers.x86_64 0:2.17-106.el7_2.1 を インストール
--> 依存性の処理をしています: kernel-headers >= 2.2.1 のパッケージ: glibc-headers-2.17-106.el7_2.1.x86_64
--> 依存性の処理をしています: kernel-headers のパッケージ: glibc-headers-2.17-106.el7_2.1.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ kernel-headers.x86_64 0:3.10.0-327.4.5.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===========================================================================================================================================
 Package                            アーキテクチャー           バージョン                                リポジトリー                 容量
===========================================================================================================================================
インストール中:
 gcc                                x86_64                     4.8.5-4.el7                               base                         16 M
依存性関連でのインストールをします:
 cpp                                x86_64                     4.8.5-4.el7                               base                        5.9 M
 glibc-devel                        x86_64                     2.17-106.el7_2.1                          updates                     1.0 M
 glibc-headers                      x86_64                     2.17-106.el7_2.1                          updates                     661 k
 kernel-headers                     x86_64                     3.10.0-327.4.5.el7                        updates                     3.2 M
 libmpc                             x86_64                     1.0.1-3.el7                               base                         51 k
 mpfr                               x86_64                     3.1.1-4.el7                               base                        203 k

トランザクションの要約
===========================================================================================================================================
インストール  1 パッケージ (+6 個の依存関係のパッケージ)

総ダウンロード容量: 27 M
インストール容量: 59 M
Is this ok [y/d/N]: y
Downloading packages:
(1/7): glibc-headers-2.17-106.el7_2.1.x86_64.rpm                                                                    | 661 kB  00:00:00     
(2/7): glibc-devel-2.17-106.el7_2.1.x86_64.rpm                                                                      | 1.0 MB  00:00:00     
(3/7): kernel-headers-3.10.0-327.4.5.el7.x86_64.rpm                                                                 | 3.2 MB  00:00:00     
(4/7): cpp-4.8.5-4.el7.x86_64.rpm                                                                                   | 5.9 MB  00:00:00     
(5/7): libmpc-1.0.1-3.el7.x86_64.rpm                                                                                |  51 kB  00:00:00     
(6/7): mpfr-3.1.1-4.el7.x86_64.rpm                                                                                  | 203 kB  00:00:00     
(7/7): gcc-4.8.5-4.el7.x86_64.rpm                                                                                   |  16 MB  00:00:00     
-------------------------------------------------------------------------------------------------------------------------------------------
合計                                                                                                        41 MB/s |  27 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : mpfr-3.1.1-4.el7.x86_64                                                                                    1/7 
  インストール中          : libmpc-1.0.1-3.el7.x86_64                                                                                  2/7 
  インストール中          : cpp-4.8.5-4.el7.x86_64                                                                                     3/7 
  インストール中          : kernel-headers-3.10.0-327.4.5.el7.x86_64                                                                   4/7 
  インストール中          : glibc-headers-2.17-106.el7_2.1.x86_64                                                                      5/7 
  インストール中          : glibc-devel-2.17-106.el7_2.1.x86_64                                                                        6/7 
  インストール中          : gcc-4.8.5-4.el7.x86_64                                                                                     7/7 
  検証中                  : gcc-4.8.5-4.el7.x86_64                                                                                     1/7 
  検証中                  : cpp-4.8.5-4.el7.x86_64                                                                                     2/7 
  検証中                  : glibc-devel-2.17-106.el7_2.1.x86_64                                                                        3/7 
  検証中                  : mpfr-3.1.1-4.el7.x86_64                                                                                    4/7 
  検証中                  : kernel-headers-3.10.0-327.4.5.el7.x86_64                                                                   5/7 
  検証中                  : glibc-headers-2.17-106.el7_2.1.x86_64                                                                      6/7 
  検証中                  : libmpc-1.0.1-3.el7.x86_64                                                                                  7/7 

インストール:
  gcc.x86_64 0:4.8.5-4.el7                                                                                                                 

依存性関連をインストールしました:
  cpp.x86_64 0:4.8.5-4.el7                        glibc-devel.x86_64 0:2.17-106.el7_2.1      glibc-headers.x86_64 0:2.17-106.el7_2.1     
  kernel-headers.x86_64 0:3.10.0-327.4.5.el7      libmpc.x86_64 0:1.0.1-3.el7                mpfr.x86_64 0:3.1.1-4.el7                   

完了しました!
New leaves:
  gcc.x86_64

mecab-develのインストール

次に、mecab-betaに必要なmecab-configを用意するため、mecab-develをインストールします。mecab-configが存在するかどうかは、which mecab-config で確認できます。

mecab-develのインストール
sudo yum install mecab-devel
読み込んだプラグイン:fastestmirror, remove-with-leaves, show-leaves
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ mecab-devel.x86_64 0:0.996-1.el7.centos.1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===========================================================================================================================================
 Package                          アーキテクチャー            バージョン                                リポジトリー                  容量
===========================================================================================================================================
インストール中:
 mecab-devel                      x86_64                      0.996-1.el7.centos.1                      groonga                       73 k

トランザクションの要約
===========================================================================================================================================
インストール  1 パッケージ

総ダウンロード容量: 73 k
インストール容量: 714 k
Is this ok [y/d/N]: y
Downloading packages:
mecab-devel-0.996-1.el7.centos.1.x86_64.rpm                                                                         |  73 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : mecab-devel-0.996-1.el7.centos.1.x86_64                                                                    1/1 
  検証中                  : mecab-devel-0.996-1.el7.centos.1.x86_64                                                                    1/1 

インストール:
  mecab-devel.x86_64 0:0.996-1.el7.centos.1                                                                                                

完了しました!
New leaves:
  mecab-devel.x86_64

mecab-betaのインストール時に必要なため、mecab-configのフルパスを調べます。

mecab-configのフルパスを調べる
which mecab-config
/usr/bin/mecab-config

mecab-betaのインストール

mecab-betaのインストールをします。インストールの途中で、specify pathname to mecab-config [no] : と聞かれるので、先ほど調べたmecab-configのフルパス /usr/bin/mecab-config を指定します。

mecab-betaのインストール
sudo pear install opendogs/mecab-beta
downloading mecab-0.6.0.tgz ...
Starting to download mecab-0.6.0.tgz (50,194 bytes)
.............done: 50,194 bytes
8 source files, building
running: phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
specify pathname to mecab-config [no] : /usr/bin/mecab-config
building in /var/tmp/pear-build-root6Im9wg/mecab-0.6.0
running: /var/tmp/mecab/configure --with-mecab=/usr/bin/mecab-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -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
checking for PHP extension directory... /usr/lib64/php/modules
checking for PHP installed headers prefix... /usr/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable MeCab support... yes, shared
checking for mecab-config... /usr/bin/mecab-config
checking for MeCab library version... 0.996 (ok)
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking mecab.h usability... yes
checking mecab.h presence... yes
checking for mecab.h... yes
checking for mecab_new2 in -lmecab... yes
checking for PHP version... build for 5.4.16
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) gawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for mt... no
checking if : is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands
running: make
/bin/sh /var/tmp/pear-build-root6Im9wg/mecab-0.6.0/libtool --mode=compile cc  -I. -I/var/tmp/mecab -DPHP_ATOM_INC -I/var/tmp/pear-build-root6Im9wg/mecab-0.6.0/include -I/var/tmp/pear-build-root6Im9wg/mecab-0.6.0/main -I/var/tmp/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  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/mecab/mecab5.c -o mecab5.lo
libtool: compile:  cc -I. -I/var/tmp/mecab -DPHP_ATOM_INC -I/var/tmp/pear-build-root6Im9wg/mecab-0.6.0/include -I/var/tmp/pear-build-root6Im9wg/mecab-0.6.0/main -I/var/tmp/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 -DHAVE_CONFIG_H -g -O2 -c /var/tmp/mecab/mecab5.c  -fPIC -DPIC -o .libs/mecab5.o
/bin/sh /var/tmp/pear-build-root6Im9wg/mecab-0.6.0/libtool --mode=link cc -DPHP_ATOM_INC -I/var/tmp/pear-build-root6Im9wg/mecab-0.6.0/include -I/var/tmp/pear-build-root6Im9wg/mecab-0.6.0/main -I/var/tmp/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  -DHAVE_CONFIG_H  -g -O2   -o mecab.la -export-dynamic -avoid-version -prefer-pic -module -rpath /var/tmp/pear-build-root6Im9wg/mecab-0.6.0/modules  mecab5.lo -Wl,-rpath,/usr/lib64 -L/usr/lib64 -lmecab
libtool: link: cc -shared  -fPIC -DPIC  .libs/mecab5.o   -L/usr/lib64 -lmecab  -O2 -Wl,-rpath -Wl,/usr/lib64   -Wl,-soname -Wl,mecab.so -o .libs/mecab.so
libtool: link: ( cd ".libs" && rm -f "mecab.la" && ln -s "../mecab.la" "mecab.la" )
/bin/sh /var/tmp/pear-build-root6Im9wg/mecab-0.6.0/libtool --mode=install cp ./mecab.la /var/tmp/pear-build-root6Im9wg/mecab-0.6.0/modules
libtool: install: cp ./.libs/mecab.so /var/tmp/pear-build-root6Im9wg/mecab-0.6.0/modules/mecab.so
libtool: install: cp ./.libs/mecab.lai /var/tmp/pear-build-root6Im9wg/mecab-0.6.0/modules/mecab.la
libtool: finish: PATH="/usr/bin:/sbin:/bin:/usr/sbin:/usr/bin:/sbin" ldconfig -n /var/tmp/pear-build-root6Im9wg/mecab-0.6.0/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /var/tmp/pear-build-root6Im9wg/mecab-0.6.0/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/var/tmp/pear-build-root6Im9wg/install-mecab-0.6.0" install
Installing shared extensions:     /var/tmp/pear-build-root6Im9wg/install-mecab-0.6.0/usr/lib64/php/modules/
running: find "/var/tmp/pear-build-root6Im9wg/install-mecab-0.6.0" | xargs ls -dils
  672680   0 drwxr-xr-x 3 root root     16  2月 12 19:30 /var/tmp/pear-build-root6Im9wg/install-mecab-0.6.0
52681625   0 drwxr-xr-x 3 root root     18  2月 12 19:30 /var/tmp/pear-build-root6Im9wg/install-mecab-0.6.0/usr
  672681   0 drwxr-xr-x 3 root root     16  2月 12 19:30 /var/tmp/pear-build-root6Im9wg/install-mecab-0.6.0/usr/lib64
17038105   0 drwxr-xr-x 3 root root     20  2月 12 19:30 /var/tmp/pear-build-root6Im9wg/install-mecab-0.6.0/usr/lib64/php
34769324   0 drwxr-xr-x 2 root root     21  2月 12 19:30 /var/tmp/pear-build-root6Im9wg/install-mecab-0.6.0/usr/lib64/php/modules
34769325 240 -rwxr-xr-x 1 root root 241723  2月 12 19:30 /var/tmp/pear-build-root6Im9wg/install-mecab-0.6.0/usr/lib64/php/modules/mecab.so

Build process completed successfully
Installing '/usr/lib64/php/modules/mecab.so'
install ok: channel://pecl.opendogs.org/mecab-0.6.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=mecab.so" to php.ini

PHP拡張モジュールの追加設定

php.iniに拡張モジュールの追加設定をします。

php.iniの編集
sudo vim /etc/php.ini
以下の記述を追加
;mecab
extension=/usr/lib64/php/modules/mecab.so

設定反映のためにApacheを再起動します。

Apache再起動
apachectl restart
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: user1
Password: 
==== AUTHENTICATION COMPLETE ===

動作確認

PHPから形態素解析ができることを確認します。

PHPファイルの作成
vim mecab_test.php
形態素解析のサンプル
<?php
$mecab = new MeCab_Tagger();
$str = "すもももももももものうち";
var_dump($mecab->parse($str));
サンプルの実行
php mecab_test.php 
string(353) "すもも  名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも  名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも  名詞,一般,*,*,*,*,もも,モモ,モモ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
うち  名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
EOS
"
16
15
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
16
15