LoginSignup
0
1

More than 5 years have passed since last update.

PHPにPECLでSolr extentionを導入する

Posted at

概要

Apache SolrをPHPから操作するSolr Extensionを導入します。
Apache Solr自体の導入は解説しません。
Solr Extensionの使い方も解説しません。1

環境

  • CentOS7 64bit
  • PHP5.4

必要ライブラリのyum install

通常はpecl installのときにエラーとしてインストールを促されます。
不要なものをインストールしたくない方はpecl installを先に試して、エラーメッセージの指示に従うのもOKです。

yum install libcurl-devel
yum install libxml2-devel

ない場合はlibcurlを再インストールしてね、と言う風に読めるエラーがでますが、インストールするのは*-develです。
ビルドするときに必要なのでしょうが、ぺちぱーの中にはビルドの概念が薄い方もいらっしゃるのではないでしょうか。私のことです。

Solr Extension インストール

pecl install solr
を実行する。
入力はデフォルトのままでよい。

導入時エラー例
[root@localhost ~]# pecl install solr
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading solr-2.4.0.tgz ...
Starting to download solr-2.4.0.tgz (256,316 bytes)
.....................................................done: 256,316 bytes
64 source files, building
running: phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
Enable Solr Debugging (Compiles solr in debug mode) [no] :
libcURL install prefix [/usr] :
libxml2 install prefix [/usr] :
(中略)
configure: error: Please reinstall the libcurl distribution -
        easy.h should be in <curl-dir>/include/curl/
ERROR: `/var/tmp/solr/configure --with-php-config=/usr/bin/php-config --enable-solr-debug=no --with-curl=/usr --with-libxml-dir=/usr' failed

Solr Extension 有効化

インストールしただけではまだ使えず、PHPに読み込ませなくてはいけない。
php.iniに書くべきものは、Extensionを探すパス(include Path)と、Extensionファイルの名前だが、Extensionファイルの作成先がすでにパス指定されているので、パスの指定は追加しなくてもよい。

[root@localhost ~]# php -i | grep 'extension'
This extension makes use of Bstrlib available at http://bstrlib.sf.net
extension_dir => /usr/lib64/php/modules => /usr/lib64/php/modules
[root@localhost ~]# ll /usr/lib64/php/modules/solr.so
-rw-r--r-- 1 root root 1302950 Aug  2 17:34 /usr/lib64/php/modules/solr.so

ファイル名を記述するだけで良いのだが、php.iniに書かずとも、/etc/php.d/に書かれたものも読み込まれるので、綺麗にできる。
むしろExtensionは/etc/php.d/に書かれているので、Solrもここに書く。

echo 'extension=solr.so' > /etc/php.d/solr.ini

これで有効化が完了した

[root@localhost ~]# php -i | grep 'Solr'
Solr Support => enabled

Apacheなどは再読み込みが必要。
systemctl restart httpd.service


  1. むしろ誰か解説してくださいお願いします。 

0
1
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
0
1