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

ヘルプ:PHP7.2でAPCu+OPcacheを使う(CentOS7)

メインページ > ヘルプ:目次 > ヘルプ:自宅サーバー構築(CentOS7)  > PHP7.2でAPCu+OPcacheを使う(CentOS7)

PHPは5.5以降、APCからZend OPcache+APCuに変わりました。 APCはインストールしてiniファイルを編集したりするだけでopecode cacheとdata cacheを勝手に上手い具合にやってくれましたが、APCuは自分で使うようなスクリプトを書かなければなりません。

  • テスト用自宅サーバーで、動作確認しています。導入される方は自己責任で行ってください。
  • EPELリポジトリ、Remiリポジトリを導入済みとします。
  • MediaWiki 1.30.0 動作しました。
  • WordPress 4.9.5 動作しました。

インストール

PHP7をyumで入れていれば、おそらく同じリポジトリでAPCuとOPcacheもあるはずですので、yum installできます。

[root@host4 ~]# yum --enablerepo=remi-php72 install php-pecl-apcu php-opcache

設定

APCu のメモリ使用量

[root@host4 ~]# vi /etc/php.d/40-apcu.ini
## APCuの最大メモリ使用量を32MB → 16MB
;apc.shm_size=32M

apc.shm_size=16M

OPcache メモリ使用量

[root@host4 ~]# vi /etc/php.d/10-opcache.ini

; The OPcache shared memory storage size.
## OPcacheの最大メモリ使用量を128MB → 256MB
opcache.memory_consumption=128

opcache.memory_consumption=256

アクセス制限

ローカルからのみアクセス出来るように設定する。

[root@host4 ~]# vi /etc/httpd/conf.d/apc.conf

<Directory /var/www/html/awajp.com/apc>
   Order Deny,Allow
   Deny from all
   Allow from 127.0.0.1 192.168.1.0/24
</Directory>

[root@host4 ~]# vi /etc/httpd/conf.d/opcache-status.conf

<Directory /var/www/html/awajp.com/opcache-status>
   Order Deny,Allow
   Deny from all
   Allow from 127.0.0.1 192.168.1.0/24
</Directory>

Webサーバー再起動

[root@host4 ~]# systemctl restart httpd

Webサーバーステータス

[root@host4 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 土 2018-04-07 08:47:34 JST; 10s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 20724 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 20730 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           tq20730 /usr/sbin/httpd -DFOREGROUND
           tq20731 /usr/sbin/httpd -DFOREGROUND
           tq20732 /usr/sbin/httpd -DFOREGROUND
           tq20733 /usr/sbin/httpd -DFOREGROUND
           tq20734 /usr/sbin/httpd -DFOREGROUND
           mq20735 /usr/sbin/httpd -DFOREGROUND

 4月 07 08:47:34 host4.awajp.com systemd[1]: Starting The Apache HTTP Server...
 4月 07 08:47:34 host4.awajp.com systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.