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

提供:EELの自由帳

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

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.2をdnfで入れていれば、おそらくAPCuとOPcacheもあるはずです。

[root@host3 ~]# dnf install php-pecl-apcu php-opcache

設定

APCu のメモリ使用量

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

apc.shm_size=16M

OPcache メモリ使用量

[root@host3 ~]# 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@host3 ~]# vi /etc/httpd/conf.d/apc.conf

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

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

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

Webサーバー再起動

[root@host3 ~]# systemctl restart httpd

Webサーバーステータス

[root@host3 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           mqphp-fpm.conf
   Active: active (running) since Tue 2020-03-10 21:05:30 JST; 25s ago
     Docs: man:httpd.service(8)
 Main PID: 1832 (httpd)
   Status: "Running, listening on: port 443, port 80"
    Tasks: 213 (limit: 26213)
   Memory: 43.9M
   CGroup: /system.slice/httpd.service
           tq1832 /usr/sbin/httpd -DFOREGROUND
           tq1833 /usr/sbin/httpd -DFOREGROUND
           tq1834 /usr/sbin/httpd -DFOREGROUND
           tq1835 /usr/sbin/httpd -DFOREGROUND
           mq1836 /usr/sbin/httpd -DFOREGROUND

 3月 10 21:05:30 host3.sudachi.jp systemd[1]: Starting The Apache HTTP Server...
 3月 10 21:05:30 host3.sudachi.jp systemd[1]: Started The Apache HTTP Server.
 3月 10 21:05:30 host3.sudachi.jp httpd[1832]: Server configured, listening on: port 443, port 80