ホーム » ブログ » 2008年09月 » Tritonn(MySQL+Senna)+Mecab+Apahce+PHPをCentOS5にインストールする

Tritonn(MySQL+Senna)+Mecab+Apahce+PHPをCentOS5にインストールする

2008-09-12 written by akiyan | このエントリーを含むはてなブックマーク このエントリーを含むはてなブックマーク

PHPからTritonn(MySQL+Senna)を使うためのセットアップに若干ハマったので、メモ的にエントリー。

Tritonn(MySQL+Senna)だけでPHPからMySQLに接続するときは、Tritonnをソースからインストールしなくてはなりません。Tritonnプロジェクトではコンパイル済みのrpmをリリースしていますが、このrpmにはmysql-devel的なライブラリが同梱されていません。Tritonnだけをrpmからインストールした場合、PHPの./configure時にlibmysqlclient.soが見つからず、PHPのインストールを完了させることができないのです。(参考:tritonをphpから使う : 社長にはなれない僕だから。

mysql-develを別からインストールしてもよいのですが、可能な限りはシンプルに済ませたいところです。

Tritonnをソースからインストールするおおまかな手順は以下の通りです。環境は CentOS5.2(32bit)をVMware Server(Win32)のゲストOSとして動作させています。

  1. 既存のMySQLを削除する(あれば)
  2. MySQL用のユーザーグループをユーザーを作成する
  3. コンパイルに必要なもろもろのモジュールをyumでインストールする
  4. Mecabをソースからインストール
  5. Sennaをソースからインストール
  6. Tritonnをソースからインストール
  7. Apacheをソースからインストール
  8. PHPをソースからインストール

詳細な手順は以下の通りです。

## MySQLを削除する
$ sudo yum remove mysql

## MySQL用のユーザーグループをユーザーを作成する
$ sudo /usr/sbin/groupadd mysql
$ sudo /usr/sbin/useradd -g mysql mysql

## コンパイルに必要なもろもろのモジュールをyumでインストールする
$ sudo yum -y install \
gcc-c++ gcc-java gcc-objc gcc4 gcc4-c++ autoconf \
libtool automake bison ncurses-devel libtool-ltdl libtool-ltdl-devel
  ( http://blog.livedoor.jp/k1LoW/archives/53521855.html を参考に、
    libtool-ltdl libtool-tdl-devel を加えました )

## 作業用にユーザーディレクトリに srcディレクトリを作成
$ mkdir ~/src

## Mecabをソースからインストール
$ cd ~/src
$ wget http://nchc.dl.sourceforge.net/sourceforge/mecab/mecab-0.97.tar.gz
  ( http://mecab.sourceforge.net/ から最新版の取得を推奨します )
$ tar zxvf mecab-0.97.tar.gz
$ cd mecab-0.97
$ ./configure --prefix=/usr --with-charset=utf8
$ make
$ sudo make install

## Mecab-IPA辞書をソースからインストール
$ cd ~/src
$ wget http://nchc.dl.sourceforge.net/sourceforge/mecab/mecab-ipadic-2.7.0-20070801.tar.gz 
  ( http://mecab.sourceforge.net/ から最新版の取得を推奨します )
$ tar zxvf mecab-ipadic-2.7.0-20070801.tar.gz
$ cd mecab-ipadic-2.7.0-20070801
$ ./configure --prefix=/usr --with-charset=utf8
$ make
$ sudo make install

## Sennaをソースからインストール
$ cd ~/src
$ wget http://keihanna.dl.sourceforge.jp/senna/31533/senna-1.1.3.tar.gz
  ( http://qwik.jp/senna/Download.html から最新版の取得を推奨します )
$ tar zxvf senna-1.1.3.tar.gz
$ cd senna-1.1.3
$ ./configure --prefix=/usr
$ make
  ( ここでコンパイラがメモリを200MB以上確保するときがあるので、
    ゲストOSの場合は最低でも512MBは割り当てたほうがよいです )
$ sudo make install

## Tritonnをソースからインストール
$ cd ~/src
$ wget http://globalbase.dl.sourceforge.jp/tritonn/31597/tritonn-1.0.10-mysql-5.0.51a.tar.gz 
  ( http://qwik.jp/tritonn/download.html から最新版の取得を推奨します )
$ tar zxvf tritonn-1.0.10-mysql-5.0.51a.tar.gz
$ cd tritonn-1.0.10-mysql-5.0.51a
$ CC='gcc' CXX='gcc' \
./configure \
'--prefix=/usr/local/mysql' \
'--localstatedir=/usr/local/mysql/data' \
'--libexecdir=/usr/local/mysql/bin' \
'--enable-thread-safe-client' \
'--enable-local-infile' \
'--enable-assembler' \
'--with-pic' \
'--with-fast-mutexes' \
'--with-client-ldflags=-static' \
'--with-mysqld-ldflags=-static' \
'--with-zlib-dir=bundled' \
'--with-big-tables' \
'--with-yassl' \
'--with-readline' \
'--with-archive-storage-engine' \
'--with-blackhole-storage-engine' \
'--with-ndbcluster' \
'--with-csv-storage-engine' \
'--with-example-storage-engine' \
'--with-federated-storage-engine' \
'--with-innodb' \
'--with-extra-charsets=complex' \
'--with-senna' '--with-mecab'

  ( コンパイルオプションは http://qwik.jp/tritonn/howtobuild.html と、
    http://d.hatena.ne.jp/mir/20070803/p2 を参考にしました )

$ make
$ sudo make install

## サービスへ「mysqld」として登録
$ sudo cp ./support-files/mysql.server /etc/init.d/mysqld
$ sudo chmod 755 /etc/init.d/mysqld
$ sudo /sbin/chkconfig --add mysqld

## DBを初期化し、ユーザーとグループを適切なものに変更
$ sudo /usr/local/mysql/bin/mysql_install_db -umysql
  ( /usr/local/mysql/data 内にDBのファイルが初期化されます )
$ sudo chown -R mysql /usr/local/mysql/data
$ sudo chgrp -R mysql /usr/local/mysql

## MySQLを起動する
$ sudo /usr/local/mysql/bin/mysqld_safe -umysql &

## MySQLの起動に成功すると以下のようなメッセージが出力される
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
080911  2:07:27  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
080911  2:07:27  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
080911  2:07:27  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
080911  2:07:28  InnoDB: Started; log sequence number 0 0
080911  2:07:28 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.0.51a'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server (GPL)

$ /usr/local/mysql/bin/mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.51a MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> \q
Bye

## mysqlを終了する
$ /usr/local/mysql/bin/mysqladmin -uroot shutdown

## serviceから起動してみる
$ sudo /sbin/service mysqld start
Starting MySQL.                                            [  OK  ]

## Apache (apr, apr-util, httpd) をソースからインストール
$ cd ~/src
$ wget http://www.meisei-u.ac.jp/mirror/apache/httpd/httpd-2.2.9.tar.gz
$ tar zxvf httpd-2.2.9.tar.gz
$ cd httpd-2.2.9/srclib/apr/

## aprのインストール
$ ./configure
$ make
$ sudo make install

## apr-utilのインストール
$ cd ../apr-util
$ ./configure --with-apr=/usr/local/apr
$ make
$ sudo make install

## httpdのインストール
$ cd ../..
$ ./configure \
--enable-so \
--enable-mods-shared=all \
--enable-modules=all \
--with-mpm=prefork \
--with-apr=/usr/local/apr/
$ make
$ sudo make install

## サービスへ「httpd」として登録
$ sudo cp build/rpm/httpd.init /etc/init.d/httpd
$ sudo chmod 755 /etc/init.d/httpd
$ sudo /sbin/chkconfig --add httpd

## /etc/init.d/httpd を修正する
$ sudo vi /etc/init.d/httpd

(以下の3行を修正)

- apachectl=/usr/sbin/apachectl 
+ apachectl=/usr/local/apache2/bin/apachectl
- httpd=${HTTPD-/usr/sbin/httpd}
+ httpd=${HTTPD-/usr/local/apache2/bin/httpd]
-      CONFFILE=/etc/httpd/conf/httpd.conf
+      CONFFILE=/usr/local/apache2/conf/httpd.conf

## PHPをソースからインストール
$ sudo yum install -y \
libmcrypt-devel libxml2 libxml2-devel libpng libpng-devel \
libjpeg libjpeg-devel curl curl-devel
$ cd ~/src
$ wget http://jp.php.net/get/php-5.2.6.tar.gz/from/this/mirror
$ tar zxvf php-5.2.6.tar.gz
$ cd php-5.2.6
$ './configure' \
'--prefix=/usr/local' \
'--with-mysql=/usr/local/mysql' \
'--with-pdo-mysql=/usr/local/mysql' \
'--with-apxs2=/usr/local/apache2/bin/apxs' \
'--enable-mbstring' \
'--enable-mbregex' \
'--with-jpeg-dir' \
'--enable-ftp' \
'--enable-exif' \
'--enable-sockets' \
'--with-openssl' \
'--with-zlib' \
'--with-gd' \
'--with-curl' \
'--enable-zend-multibyte' \
'--enable-pcntl' \
'--with-mcrypt'
$ make
$ sudo make install

## httpdの起動
$ sudo /sbin/service httpd start
Starting httpd:                                            [  OK  ]

あとは http://qwik.jp/tritonn/basictutorial.html を見てチュートリアルを試すなり、PHPから接続してみるなりして動作確認をしてください。

2008-09-12 written by akiyan | 記事 | このエントリーを含むはてなブックマーク このエントリーを含むはてなブックマーク

コメント

サカえもん - 2008-09-15 14:02:03

CentOSでメンテナンス性を考えるなら、SRPMのSPECファイルを書き換えてrpmbuildするという方法もありますよ。ちょっと面倒ですが。

投稿



本文と関連性の無いコメントは削除することがあります。予めご了承ください。

トラックバック

このエントリへのトラックバックURLは
http://www.akiyan.com/cgi/mt/mt-tb.cgi/1469
です。トラックバック元のエントリに当サイトへのリンクが無い場合はトラックバックを削除することがあります。