MySQL5.0.67+senna全文検索+PHP5.2.4をEC2に導入

MySQL5.0.67+senna全文検索+PHP5.2.4をEC2に導入

インスタンス

amzn-ami-minimal-pv-2013.09.0.x86_64-ebs (ami-0b61fe0a)
サイズは10Gで作成

必要モジュールの導入

MySQLたち
Mysql-devel http://downloads.mysql.com/archives/get/file/MySQL-devel-5.0.67-0.glibc23.x86_64.rpm
Mysql-shared http://downloads.mysql.com/archives/get/file/MySQL-shared-5.0.67-0.glibc23.x86_64.rpm
Mysql-server http://downloads.mysql.com/archives/get/file/MySQL-server-5.0.67-0.glibc23.x86_64.rpm
Mysql-client http://downloads.mysql.com/archives/get/file/MySQL-client-5.0.67-0.glibc23.x86_64.rpm

sudo yum install wget perl perl-DBI gcc gcc-c++ ncurses-devel
$ sudo wget http://downloads.mysql.com/archives/get/file/MySQL-devel-5.0.67-0.glibc23.x86_64.rpm
$ sudo wget http://downloads.mysql.com/archives/get/file/MySQL-shared-5.0.67-0.glibc23.x86_64.rpm
$ sudo wget http://downloads.mysql.com/archives/get/file/MySQL-server-5.0.67-0.glibc23.x86_64.rpm
$ sudo wget http://downloads.mysql.com/archives/get/file/MySQL-client-5.0.67-0.glibc23.x86_64.rpm
$ sudo rpm -i MySQL-devel-5.0.67-0.glibc23.x86_64.rpm
$ sudo rpm -i MySQL-shared-5.0.67-0.glibc23.x86_64.rpm 
$ sudo rpm -i MySQL-client-5.0.67-0.glibc23.x86_64.rpm
$ sudo rpm -i MySQL-server-5.0.67-0.glibc23.x86_64.rpm  

めかぶを入れる

本体

mecab http://mecab.googlecode.com/files/mecab-0.991.tar.gz

$ sudo wget http://mecab.googlecode.com/files/mecab-0.991.tar.gz
$ tar xvzf mecab-0.991.tar.gz
$ cd mecab-0.991
$ sudo ./configure --prefix=/usr/local/mecab --with-charset=utf8 | sudo tee configure.log.2014-06-19
$ sudo make 2>&1 | sudo tee make.log.2014-06-19
$ sudo make install 2>&1 | sudo tee make-install.log.2014-06-19
$ /usr/local/mecab/bin/mecab -v
mecab of 0.991

辞書

mecab-ipadic http://mecab.googlecode.com/files/mecab-ipadic-2.7.0-20070801.tar.gz

$ sudo wget http://mecab.googlecode.com/files/mecab-ipadic-2.7.0-20070801.tar.gz
$ sudo tar xvf mecab-ipadic-2.7.0-20070801.tar.gz
$ cd mecab-ipadic-2.7.0-20070801
$ sudo ./configure --prefix=/usr/local/mecab/ipadic --with-mecab-config=/usr/local/mecab/bin/mecab-config --with-charset=utf8 | sudo tee configure.log.2014-06-19
$ sudo make 2>&1 | sudo tee make.log.2014-06-19
$ sudo make install 2>&1 | sudo tee make-install.log.2014-06-19

sennaを入れる

senna http://globalbase.dl.sourceforge.jp/senna/46945/senna-1.1.5.tar.gz

$ sudo wget http://globalbase.dl.sourceforge.jp/senna/46945/senna-1.1.5.tar.gz
$ sudo tar xvf senna-1.1.5.tar.gz
$ cd senna-1.1.5
$ sudo ./configure --prefix=/usr/local/mysql_senna --with-mecab --with-mecab-config=/usr/local/mecab/bin/mecab-config --with-charset=utf8 | sudo tee configure.log.2014-06-19

makeをするとnkfc.cで止まるので、先にnkfc.cのコンパイルを行う

$ cd lib; sudo ../libtool --tag=CC --mode=compile \
gcc -I. -I.. -Wall -O0 -fno-strict-aliasing -g -MT nfkc.lo \
-MD -MP -MF .deps/nfkc.Plo -c -o nfkc.lo nfkc.c
$ cd ../

make

$ sudo make 2>&1 | sudo tee make.log.2014-06-19
$ sudo make install 2>&1 | sudo tee make-install.log.2014-06-19
#ownerをmysqlにしておく
$ sudo chown -R mysql:mysql /usr/local/mysql_senna/

tritonnを入れる

tritonn http://globalbase.dl.sourceforge.jp/tritonn/36449/tritonn-1.0.12-mysql-5.0.67.tar.gz”

$ sudo wget http://globalbase.dl.sourceforge.jp/tritonn/36449/tritonn-1.0.12-mysql-5.0.67.tar.gz
$ sudo tar xvf tritonn-1.0.12-mysql-5.0.67.tar.gz
$ cd tritonn-1.0.12-mysql-5.0.67
$ sudo ./configure --prefix=/usr/local/mysql_senna --enable-thread-safe-client --with-charset=utf8 --with-extra-charsets=all --with-readline --with-mecab=/usr/local/mecab --with-senna=/usr/local/senna | sudo tee configure.log.2014-06-19
$ sudo make 2>&1 | sudo tee make.log.2014-06-19
$ sudo make install 2>&1 | sudo tee make-install.log.2014-06-19

tritonn内のmy.cnfをコピーしてmysql.sockの場所を変更

$ sudo cp support-files/my-medium.cnf /etc/my.cnf
/etc/my.cnf
[client]
#password       = your_password
port            = 3306
socket          = /var/lib/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /var/lib/mysql/mysql.sock

mysql_install_db実行

$ sudo /usr/local/mysql_senna/bin/mysql_install_db --user=mysql --skip-name-resolve
$ sudo /usr/local/mysql_senna/share/mysql/mysql.server start

自動起動設定

$ cd /tmp/tritonn-1.0.12-mysql-5.0.67/support-files/
$ sudo cp -p mysql.server mysql
$ sudo chmod +x mysql
$ sudo mv mysql /etc/init.d/
$ cd /etc/rc2.d/
$ sudo ln -s ../init.d/mysql S90mysql

Apache設定

必要なものをインストールしていく

$ sudo yum install httpd httpd-devel libxml2 libxml2-devel
PHP

PHP 5.2.4 http://museum.php.net/php5/php-5.2.4.tar.gz

$ sudo wget http://museum.php.net/php5/php-5.2.4.tar.gz
$ ./configure --with-apxs2=/usr/sbin/apxs --with-iconv --enable-mbstring --with-mysqli=/usr/local/mysql_senna/bin/mysql_config --with-mysql=/usr/local/mysql_senna/bin/mysql_config --with-libxml-dir=/usr/include/libxml2 | sudo tee configure.log.2014-06-20

このままconfigureが通ってもmakeでエラーが出る(make: *** [ext/dom/node.lo] エラー 1)のでlibxml2にパッチをあてる
パッチがうまくあたらなかったら該当箇所を自力で変更する。一応書き換え前のファイルもcpしておく。

php-5.2_libxml2.patch

--- ext/dom/node.c  2012-08-06 17:49:48.826716692 +0800
+++ ext/dom/node.c  2012-08-06 17:52:47.633484660 +0800
@@ -1895,9 +1895,17 @@ static void dom_canonicalization(INTERNA
         RETVAL_FALSE;
     } else {
        if (mode == 0) {
+#ifdef LIBXML2_NEW_BUFFER
+            ret = xmlOutputBufferGetSize(buf);
+#else
            ret = buf->buffer->use;
+#endif
            if (ret > 0) {
+#ifdef LIBXML2_NEW_BUFFER
+                RETVAL_STRINGL((char *) xmlOutputBufferGetContent(buf), ret, 1);
+#else
                RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
+#endif
            } else {
                RETVAL_EMPTY_STRING();
            }
--- ext/dom/documenttype.c  2012-08-06 18:02:16.019640870 +0800
+++ ext/dom/documenttype.c  2012-08-06 18:06:16.612228905 +0800
@@ -205,7 +205,13 @@ int dom_documenttype_internal_subset_rea
        if (buff != NULL) {
            xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL);
            xmlOutputBufferFlush(buff);
+
+#ifdef LIBXML2_NEW_BUFFER
+           ZVAL_STRINGL(*retval, xmlOutputBufferGetContent(buff),
+                        xmlOutputBufferGetSize(buff), 1);
+#else
            ZVAL_STRINGL(*retval, buff->buffer->content, buff->buffer->use, 1);
+#endif
            (void)xmlOutputBufferClose(buff);
            return SUCCESS;
        }
--- ext/simplexml/simplexml.c   2012-08-06 18:10:44.621017026 +0800
+++ ext/simplexml/simplexml.c   2012-08-06 18:12:48.016270419 +0800
@@ -1417,7 +1417,12 @@ SXE_METHOD(asXML)

            xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, ((xmlDocPtr) sxe->document->ptr)->encoding);
            xmlOutputBufferFlush(outbuf);
+#ifdef LIBXML2_NEW_BUFFER
+           RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf),
+                          xmlOutputBufferGetSize(outbuf), 1);
+#else
            RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use, 1);
+#endif
            xmlOutputBufferClose(outbuf);
        }
    } else {

$ sudo yum install patch
$ cd /tmp/php-5.2.4/
$ patch -p0 < /tmp/php-5.2_libxml2.patch

node.cのエラーは出なくなったけど、documenttype.cでエラーが出るので(make: *** [ext/dom/documenttype.lo] エラー 1)直接書き換え

error
/tmp/php-5.2.4/ext/dom/documenttype.c:219:42: error: dereferencing pointer to incomplete type
    strintsubset = xmlStrndup(buff->buffer->content, buff->buffer->use);

こういうエラーなので、以下の通り修正

php-5.2.4/ext/dom/documenttype.c

#この行を
strintsubset = xmlStrndup(buff->buffer->content, buff->buffer->use);
#こう
strintsubset = xmlStrndup(xmlOutputBufferGetContent(buff), xmlOutputBufferGetSize(buff));

sudo make clean後に再度configureしてmake

$ ./configure --with-apxs2=/usr/sbin/apxs --with-iconv --enable-mbstring --with-mysqli=/usr/local/mysql_senna/bin/mysql_config --without-mysql --with-libxml-dir=/usr/include/libxml2 | sudo tee configure.log.2014-06-20
$ sudo make 2>&1 | tee make.log.2014-06-20
$ sudo make install 2>&1 | sudo tee make-install.log.2014-06-20

php.iniをコピーしてくる

$ sudo cp /tmp/php-5.2.4/php.ini-recommended /usr/local/lib/php.ini

timezoneなど基本的な部分を変更する。
DBが稼働しているかテスト(mysql -u rootでログイン。テストなのでひとまずPW設定なし。良い子は真似しちゃだめだぞ)

create table table01 (id int unsigned auto_increment not null, primary key(id), title varchar(255), body text, fulltext(body)) type=MyISAM;

insert into table01 values(null,"テストです","オレンジはorange、リンゴはappleです");

Profile picture

ぴーやま
プログラミングを嗜んでします。中華料理で出てくるたまごふわふわのコーンスープが好きです。