PHP設定 · 1 min read · Oct 24, 2025
PHP5にAPC(Alternative PHP Cache)を統合する(Fedora 8 & Apache2)
PHP5にAPC(Alternative PHP Cache)を統合する(Fedora 8 & Apache2)
バージョン 1.0
著者: Falko Timme
このガイドでは、Fedora 8システム(Apache2付き)でPHP5にAPC(Alternative PHP Cache)を統合する方法を説明します。APCは、PHP中間コードをキャッシュおよび最適化するための無料でオープンなPHPオペコードキャッシャーです。** eAcceleratorやXCacheなどの他のPHPオペコードキャッシャーと似ています。
これがあなたにとって機能するという保証はありません!
1 前提条件
私は、Apache2とPHP5がすでにインストールされて動作しているIPアドレス192.168.0.100のFedora 8サーバーでこれをテストしました。このチュートリアルでは、デモンストレーションの目的でApacheのデフォルトのドキュメントルート/var/www/htmlを使用します。もちろん、他のvhostを使用することもできますが、このチュートリアルで使用しているinfo.phpファイルへのパスを調整する必要があるかもしれません。
2 PHP5の現在の状態を確認する
まず、APCをインストールする前に、PHP5のインストール状況を確認しましょう。これを行うために、ドキュメントルート/var/www/htmlにinfo.phpファイルを作成します:
vi /var/www/html/info.php| |
その後、ブラウザでそのファイルを呼び出します:http://192.168.0.100/info.php
ご覧の通り、PHP 5.2.4がインストールされています…

…しかし、APCはページのどこにも言及されていません:

3 APCのインストール
APCはPECLを使用してインストールできるPHP拡張です。PECLはphp-pearパッケージに含まれているので、今すぐそれをインストールします:
yum install php-pearさらに、PECLがAPCをビルドできるようにするために、いくつかのAPC依存関係をインストールする必要があります:
yum install php-devel httpd-develyum groupinstall 'Development Tools'yum groupinstall 'Development Libraries'すべての依存関係がインストールされたので、次のようにAPCをインストールできます:
pecl install apc[root@server1 ~]# pecl install apc
downloading APC-3.0.18.tgz …
Starting to download APC-3.0.18.tgz (115,957 bytes)
…………………….done: 115,957 bytes
47 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
- Use apxs to set compile flags (if using APC with Apache)? : yes
1-1, ‘all’, ‘abort’, or Enter to continue: <– ENTER
[…]
———————————————————————-
Libraries have been installed in:
/var/tmp/pear-build-root/APC-3.0.18/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 theLD_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’.
running: make INSTALL_ROOT=”/var/tmp/pear-build-root/install-APC-3.0.18” install
Installing shared extensions: /var/tmp/pear-build-root/install-APC-3.0.18/usr/lib/php/modules/
running: find “/var/tmp/pear-build-root/install-APC-3.0.18” -ls
1996900 4 drwxr-xr-x 3 root root 4096 Apr 8 16:32 /var/tmp/pear-build-root/install-APC-3.0.18
1996959 4 drwxr-xr-x 3 root root 4096 Apr 8 16:32 /var/tmp/pear-build-root/install-APC-3.0.18/usr
1996960 4 drwxr-xr-x 3 root root 4096 Apr 8 16:32 /var/tmp/pear-build-root/install-APC-3.0.18/usr/lib
1996961 4 drwxr-xr-x 3 root root 4096 Apr 8 16:32 /var/tmp/pear-build-root/install-APC-3.0.18/usr/lib/php
1996962 4 drwxr-xr-x 2 root root 4096 Apr 8 16:32 /var/tmp/pear-build-root/install-APC-3.0.18/usr/lib/php/modules
1996958 432 -rwxr-xr-x 1 root root 435950 Apr 8 16:32 /var/tmp/pear-build-root/install-APC-3.0.18/usr/lib/php/modules/apc.so
Build process completed successfully
Installing ‘/usr/lib/php/modules/apc.so’
install ok: channel://pecl.php.net/APC-3.0.18
configuration option “php_ini” is not set to php.ini location
You should add “extension=apc.so” to php.ini
[root@server1 ~]# APCがインストールされたので、設定ファイル/etc/php.d/apc.iniを作成します。少なくともその中にextension=apc.soという行を追加する必要があります。他のすべての設定オプションはオプションです。利用可能なすべての設定オプションのリストはhttp://de2.php.net/manual/en/ref.apc.phpで確認できます。vi /etc/php.d/apc.ini|extension=apc.so apc.enabled=1 apc.shm_size=30| それでおしまいです。Apacheを再起動すれば完了です:/etc/init.d/httpd restartその後、再びブラウザでinfo.phpを開きます:http://192.168.0.100/info.php 今度はページにAPCが表示されるはずで、これは正常に統合され、期待通りに動作していることを意味します:
### 4 リンク - APC: http://pecl.php.net/package/APC - PHP: http://www.php.net - Apache: http://httpd.apache.org - Fedora: http://fedoraproject.org
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。