提供:すだちWiki
ヘルプ:PHP7.2でAPCu+OPcacheを使う(CentOS8)
メインページ > ヘルプ:目次 > ヘルプ:自宅サーバー構築(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@host4 ~]# dnf 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/sudachi.jp/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/sudachi.jp/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) Drop-In: /usr/lib/systemd/system/httpd.service.d └─php-fpm.conf Active: active (running) since Thu 2020-08-06 15:10:21 JST; 12s ago Docs: man:httpd.service(8) Main PID: 243034 (httpd) Status: "Running, listening on: port 443, port 80" Tasks: 213 (limit: 36050) Memory: 29.9M CGroup: /system.slice/httpd.service ├─243034 /usr/sbin/httpd -DFOREGROUND ├─243036 /usr/sbin/httpd -DFOREGROUND ├─243037 /usr/sbin/httpd -DFOREGROUND ├─243038 /usr/sbin/httpd -DFOREGROUND └─243039 /usr/sbin/httpd -DFOREGROUND 8月 06 15:10:21 host4.sudachi.jp systemd[1]: Starting The Apache HTTP Server... 8月 06 15:10:21 host4.sudachi.jp systemd[1]: Started The Apache HTTP Server. 8月 06 15:10:21 host4.sudachi.jp httpd[243034]: Server configured, listening on: port 443, port 80