PHPアクセラレータ eAccelerator のセットアップ

Debianパッケージには無いので、
SourceForge:eAccelerator (http://sourceforge.net/projects/eaccelerator/files/)から
ソース(eaccelerator-0.9.6.1.tar.bz2)をダウンロード

# cd /usr/src
# tar xvf eaccelerator-0.9.6.1.tar.bz2
# cd eaccelerator-0.9.6.1
# more README
http://www.inoshita.jp/document/README_eaccelerator-0.9.6.1
# aptitude install autoconf automake libtool m4
(全部入っていた)
# export PHP_PREFIX="/usr"
# $PHP_PREFIX/bin/phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
# ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php
-config
(略)
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate
PHP parsers.
(略)
checking for best semaphores type... configure: error: "You need to pass the use
r id eaccelerator will be running under when using sysvipc semaphores"
#

2件対処が必要で対処の順番は逆だけど楽な方は

# aptitude show re2c
パッケージ: re2c
新規: yes
状態: インストールされていません
バージョン: 0.13.5-1
(略)
# aptitude install re2c
#

もう1件が問題で、「sysvipc」って? SYSV IPCか?
セマフォーを使うならUID eacceleratorで使えるようにしないといけませんって困ったね・・・

調べたらApache実行IDを指定すれば良いそうだ

# su www-data -c id
uid=33(www-data) gid=33(www-data) 所属グループ=33(www-data)
# ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php
-config --with-eaccelerator-userid=33
# make
(略)
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/src/eaccelerator-0.9.6.1/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'.

# make install
Installing shared extensions:     /usr/lib/php5/20090626+lfs/
#

キャッシュ用ディレクトリーを作成

# mkdir /var/cache/eaccelerator
# chown www-data. /var/cache/eaccelerator
# chmod 755 /var/cache/eaccelerator

設定ファイル(eaccelerator.ini)ファイルの編集

# cp eaccelerator.ini /etc/php5/conf.d
# vi /etc/php5/conf.d/eaccelerator.ini
;extension="eaccelerator.so" ← コメントアウトすること!!
zend_extension="/usr/lib/php5/20090626+lfs/eaccelerator.so"
eaccelerator.shm_size = "16"
eaccelerator.cache_dir = "/var/cache/eaccelerator"
eaccelerator.enable = "1"
eaccelerator.optimizer = "1"
eaccelerator.debug = "0"
eaccelerator.log_file = "/var/log/apache2/eaccelerator.log"
eaccelerator.name_space = ""
eaccelerator.check_mtime = "0"
eaccelerator.filter = ""
eaccelerator.shm_ttl = "0"
eaccelerator.shm_prune_period = "0"
eaccelerator.shm_only = "0"
eaccelerator.allowed_admin_path = "/xxx/xxx/eaccelerator/control.php"

コントロール用phpファイルを(ファイル内に、user, passwordの記述があるので修正して)ブラウザで閲覧できる場所へ持っていく

# cp control.php /xxx/xxx/eaccelerator
# chmod www-data. /xxx/xxx/eaccelerator/control.php

Apacheを再起動して確認

# service apache2 restart
# php -v
PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli) (built: Aug  6 2012 19:55:36)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

以下、日本語化してある情報があったので戴いた

zend_extension
 インストール時(make install)の最終行に表示されたインストール先ディレクトリを元にモジュールファイルのフルパスを設定

eaccelerator.shm_size
 eAcceleratorが使用する共有メモリサイズをMB単位で指定
 デフォルト値は「0」でこの場合は、OSのデフォルト値を使用(OSのデフォルト値は「cat /proc/sys/kernel/shmmax」を実行して確認)

eaccelerator.cache_dir
 ディスクキャッシュを保存するディレクトリを指定
 デフォルトは「/tmp/eaccelerator」
eaccelerator.enable
 eAcceleratorを有効にするかどうを設定
 「0」無効
 「1」有効(デフォルト)

eaccelerator.optimizer
 コード実行の速度を上げるオプティマイザーを有効にするかどうを設定
 「0」無効
 「1」有効(デフォルト)

eaccelerator.debug
 デバッグモードを有効にするかどうの設定
 「0」無効
 「1」有効(デフォルト)
 有効でファイルのキャッシュヒットの情報が、ログファイルに出力される

eaccelerator.log_file
 eAcceleratorのログ出力先設定
 設定がない場合には標準エラーに出力(Apacheのエラーログに出力される)

eaccelerator.name_space
 キャッシュファイルのキー情報に付加する文字列を指定
 デフォルトの場合は、Apacheのバーチャルホストで設定されているホスト名(ServerName)が使用される

eaccelerator.check_mtime
 phpファイルの変更チェックを有効にするかどうを設定
 「0」無効
 「1」有効(デフォルト)

eaccelerator.filter
 キャッシュするファイル、キャッシュしないファイルを設定
 キャッシュするファイルを指定する場合は「*.php」など「*」を使用
 キャッシュしないファイルを指定する場合は「!*.phtml」など、先頭に「!」をつける
 あるディレクトリ「/AAAAA」にあるファイル全部をキャッシュしない場合などは、「!/AAAAAA*」とする
 デフォルト値は「”"」でこの場合には、すべてのphpファイルをキャッシュする

eaccelerator.shm_max
 キャッシュファイルの最大サイズを設定
 設定できる値は「0」「10240」「10K」「1M」
 デフォルト値は「0」で制限なしとなる

eaccelerator.shm_ttl
 新しいスクリプトをキャッシュする時に共有メモリ上に空きがない場合、設定値以上の秒数アクセスがない古いキャッシュを全て削除する
 デフォルトは「0」で削除しない

eaccelerator.shm_prune_period
 スクリプトをキャッシュする時に共有メモリ上に空きがない場合、前回のキャッシュ削除から、設定値以上の秒数が経過している場合に再度古いキャッシュを削除
 デフォルトは「0」で削除しない

eaccelerator.shm_only
 共有メモリキャッシュだけを使用(ディスクキャッシュを使用しない)するかどうを設定
 「0」共有メモリ、ディスクともに使用
 「1」共有メモリのみ

eaccelerator.compress
 キャッシュファイルの圧縮を有効にするかどうかを設定
 「0」無効
 「1」有効(デフォルト)

eaccelerator.compress_level
 キャッシュの圧縮レベルの指定
 設定できるレベルは「1」から「9」(デフォルトは「9」)

eaccelerator.keys eaccelerator.session eaccelerator.content
 それぞれのキャッシュの保存先を指定(5種類)
 「shm_and_disk」共有メモリとディスクに保存(デフォルト)
 「shm」基本的に共有メモリだがshm_sizeやshm_maxを超えた場合にはディスクに保存
 「shm_only」共有メモリにのみ保存
 「disk_only」ディスクにのみ保存
 「none」データをキャッシュしない

eaccelerator.allowed_admin_path
 eAcceleratorのコントロールファイルのフルパス

キャッシュしたくない場合は、キャッシュしたくないディレクトリに、以下の記述の「.htaccess」ファイルを置く

php_flag eaccelerator.enable 0
php_flag eaccelerator.optimizer 0
再セットアップ

phpやライブラリのバージョンアップにより再セットアップが必要になる

# php -v
[eAccelerator] This build of "eAccelerator" was compiled for PHP version 5.3.3-7+squeeze15. Rebuild it for your
PHP version (5.3.3-7+squeeze18) or download precompiled binaries.
PHP 5.3.3-7+squeeze18 with Suhosin-Patch (cli) (built: Dec 12 2013 11:34:22)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
#

make distclean (clean だけでも良さそう)を行ってコンパイル

# make distclean
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la modules/* libs/*
rm -f Makefile config.cache config.log config.status Makefile.objects Makefile.fragments libtool main/php_config.h st
amp-h sapi/apache/libphp.module buildmk.stamp/bin/grep -E define'.*include/php' /usr/src/eaccelerator-0.9.6.1/configu
re | /bin/sed 's/.*>//'|xargs rm -f
# export PHP_PREFIX="/usr"
# $PHP_PREFIX/bin/phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
# ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config --with-eaccelerator-userid=33
(略)
# make
(略)
# make install
Installing shared extensions: /usr/lib/php5/20090626+lfs/
# service apache2 restart
Restarting web server: apache2 ... waiting ..
php -v
PHP 5.3.3-7+squeeze18 with Suhosin-Patch (cli) (built: Dec 12 2013 11:34:22)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
#