提供:すだちWiki
移動先: 案内検索

ヘルプ:APCでPHPを高速化(CentOS7)

メインページ > ヘルプ:目次 > ヘルプ:自宅サーバー構築(CentOS7)  > APCでPHPを高速化(CentOS7)

APCに必要な依存パッケージのインストール

APCを、パッケージマネージャツールを使用してインストールするには、PECL、phpize、apxsコマンドと呼ばれる必要なパッケージをインストールする必要があります。

[root@host4 ~]# yum install php-pear php-devel httpd-devel pcre-devel gcc make

APCインストール

PECLコマンドを使用してAPCをインストールします。

[root@host4 ~]# pecl install apc
downloading APC-3.1.13.tgz ...
Starting to download APC-3.1.13.tgz (171,591 bytes)
.....................................done: 171,591 bytes
55 source files, building
running: phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
Enable internal debugging in APC [no] : 
Enable per request file info about files used from the APC cache [no] : 
Enable spin locks (EXPERIMENTAL) [no] : 
Enable memory protection (EXPERIMENTAL) [no] : 
Enable pthread mutexes (default) [no] : 
Enable pthread read/write locks (EXPERIMENTAL) [yes] : 
・
・
・
Build process completed successfully
Installing '/usr/lib64/php/modules/apc.so'
Installing '/usr/include/php/ext/apc/apc_serializer.h'
install ok: channel://pecl.php.net/APC-3.1.13
configuration option "php_ini" is not set to php.ini location
You should add "extension=apc.so" to php.ini

APCアップグレード

[root@host4 ~]# pecl upgrade apc
Nothing to upgrade

アップグレードは無かった。

APCのPHP拡張モジュールを有効にする

Apacheの設定において、APC拡張を有効にするには、次のコマンドを実行する。共有メモリ容量はサーバーのスペックと相談して決める必要がある。

[root@host4 ~]# vi /etc/php.d/apc.ini
extension=apc.so
; The size of each shared memory segment, with M/G suffix
apc.shm_size=512M

[root@host4 ~]# systemctl restart httpd

APCのWeb管理スクリプトを使う

APCのWeb管理スクリプトが付属しているので使えるようにしておきます。

[root@host4 ~]# mkdir /var/www/html/apc
[root@host4 ~]# cp /usr/share/pear/apc.php /var/www/html/apc/

apc.phpファイルにユーザー名とパスワードを設定してください。

[root@host4 ~]# vi /var/www/html/apc/apc.php
defaults('ADMIN_USERNAME','apc');       // Admin Username
defaults('ADMIN_PASSWORD','Set-Password-Here');  // Admin Password - CHANGE THIS TO ENABLE!!!

Webサーバー(Apache)設定ファイル新規作成

[root@host4 ~]# vi /etc/httpd/conf.d/apc.conf
<Directory /var/www/html/apc>
   Order Deny,Allow
   Deny from all
   Allow from 127.0.0.1 192.168.1.0/24 ← 内部からのアクセスのみ許可
</Directory>

[root@host4 ~]# vi /var/www/html/apc/.htaccess
DirectoryIndex apc.php

[root@host4 ~]# systemctl restart httpd ← Webサーバー再起動

Webブラウザで「http://(ホスト名またはIPアドレス)/apc/apc.php」へアクセスします。 すると以下のようにAPCの管理画面が表示され状態を確認できます。また、右上のログインボタンをクリックして、設定したユーザー名とパスワードで認証すれば全ての画面を見ることができます。

APC-1.png