php高速化 apcのインストール

APCAlternative PHP Cache)は、PHPの中間コードのキャッシュや最適化を行う拡張モジュールです。

つまり、phpが高速化されるということです。どんぐらい速くなるか計測したいけど、入れて問題が発生することはないらしい(影響がでない)ですので、phpインストール後にすぐに入れます。


インストールコマンド

# pecl install APC

エラー①

configure: error: no acceptable C compiler found in $PATH

対処方法

#yum install gcc gcc-c++

エラー②

1. Perl is not installed;
2. Apache was not compiled with DSO support (--enable-module=so);
3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs
The output of /var/tmp/pear-build-root/APC-3.0.19/y follows
/tmp/tmpaw98Nt/APC-3.0.19/configure: line 3232: /var/tmp/pear-build-root/APC-3.0.19/y: No such file or directory
configure: error: Aborting
ERROR: `/tmp/tmpaw98Nt/APC-3.0.19/configure --with-apxs=y' failed

エラーでまくりですよ(涙)


対処方法

# yum install httpd-devel
#yum install apr-devel

方法を間違えていました↓
すいません。。

正解

downloading APC-3.0.19.tgz …
Starting to download APC-3.0.19.tgz (115,735 bytes)
…………………done: 115,735 bytes
47 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20050922
Zend Extension Api No: 220051025
Use apxs to set compile flags (if using APC with Apache)? [yes] : ← 空Enter
building in /var/tmp/pear-build-kentan/APC-3.0.19
running: /tmp/tmpHKQPfO/APC-3.0.19/configure –with-apxs

apcインストール途中で質問を聞かれるが、いつものノリでYを選択してしまったのが、ハマった原因でした。
空白Enterでうまくいきます。

インストール後の設定

You should add "extension=apc.so" to php.ini

インストールが完了したときに、このように言われるので書きくわえましょう。

しかし、php.iniの他のextensionがないので不思議に思い、調査してみると間違っていました。
CentOSの場合は/etc/php.dにiniファイルを追加すれば読み込むようPHPコンパイルされているらしいです。
知りませんでした。


ですので、下記のように書きます。

# vi /etc/php.d/apc.ini
extension=apc.so
apc.ttl = 7200
apc.user_ttl = 7200

時間の設定は、下記を参考にしてください。
http://www.php.net/manual/ja/apc.configuration.php

apache再起動でOK

# /etc/init.d/httpd restart

確認

[root@testMan ~]# php -r 'phpinfo();'|grep apc
additional .ini files parsed => /etc/php.d/apc.ini,

OK入りましたね。

参考サイト

APC(Alternative PHP Cache)をCentOS5にインストール[戯言(表)]★スペシャルサンクスサイト
http://www.kentan.jp/kentan/blog/?p=233


APCpecl で CentOS5 にさくっとインストール(芸人社長)
http://blog.oowarai.com/?p=292


APC インストール時のエラー(php MySQL apache などの設定メモ)
http://web-gijyutu.com/php/apc-error.html