remiで特定バージョンのPHPをインストールしていた場合のopcache,apcuの追加インストール

【PR】
※IT系の記事は当方環境での実施内容となるため実施する場合は自己責任でお願いいたします。

お手軽な高速化のみ実施したい

WordPressの高速化を図るにあたり、なるべく影響を与えずに、お手軽に追加できる対策として
1,MySQL設定ファイルの「mysqld」セクションに記載 数字はサーバのスペックに応じて。

[mysqld]
innodb_buffer_pool_size = 512M
query_cache_size = 64M

2,yum での「opcache」,「apcu」のインストール

これらも影響少なめでよいと思っています。

が、remiとかで特定バージョンのphpをインストールしていた場合、パッケージ間の不整合を起こさずに適切なパッケージをインストールできるか不安だったので、念のため以下実施。

前提

例えばこんな感じでremiからPHP7.4をインストールしていたとします。

yum install --enablerepo=remi,remi-php74 php

まずは最新版にupdate

yum update  --enablerepo=remi,remi-php74

「opcache」,「apcu」のインストール情報を確認

yum info --enablerepo=remi,remi-php74 php-opcache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * remi: ftp.riken.jp
 * remi-php74: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: ftp.riken.jp
Available Packages
Name        : php-opcache
Arch        : x86_64
Version     : 7.4.29
Release     : 1.el7.remi
Size        : 333 k
Repo        : remi-php74
Summary     : The Zend OPcache
URL         : http://www.php.net/
License     : PHP
Description : The Zend OPcache provides faster PHP execution through opcode caching and
            : optimization. It improves PHP performance by storing precompiled script
            : bytecode in the shared memory. This eliminates the stages of reading code from
            : the disk and compiling it on future access. In addition, it applies a few
            : bytecode optimization patterns that make code execution faster.
yum info --enablerepo=remi,remi-php74 php-pecl-apcu
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * remi: ftp.riken.jp
 * remi-php74: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: ftp.riken.jp
Available Packages
Name        : php-pecl-apcu
Arch        : x86_64
Version     : 5.1.21
Release     : 1.el7.remi.7.4
Size        : 76 k
Repo        : remi-php74
Summary     : APC User Cache
URL         : https://pecl.php.net/package/APCu
License     : PHP
Description : APCu is userland caching: APC stripped of opcode caching.
            :
            : APCu only supports userland caching of variables.
            :
            : The php-pecl-apcu-bc package provides a drop
            : in replacement for APC.
            :
            : Package built for PHP 7.4.

infoの結果から今のrepo指定であればインストールパッケージに74等のバージョン数字を付加しなくとも

yum install --enablerepo=remi,remi-php74 php-pecl-apcu php-opcache

で適切なopcacheとapcuが入りそうので実行

yum install --enablerepo=remi,remi-php74 php-pecl-apcu php-opcache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * remi: ftp.riken.jp
 * remi-php74: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: ftp.riken.jp
Resolving Dependencies
--> Running transaction check
---> Package php-opcache.x86_64 0:7.4.29-1.el7.remi will be installed
---> Package php-pecl-apcu.x86_64 0:5.1.21-1.el7.remi.7.4 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
========================================================================================================================
 Package                     Arch                 Version                                Repository                Size
========================================================================================================================
Installing:
 php-opcache                 x86_64               7.4.29-1.el7.remi                      remi-php74               333 k
 php-pecl-apcu               x86_64               5.1.21-1.el7.remi.7.4                  remi-php74                76 k
 
Transaction Summary
========================================================================================================================
Install  2 Packages
 
Total download size: 408 k
Installed size: 1.3 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): php-opcache-7.4.29-1.el7.remi.x86_64.rpm                                                  | 333 kB  00:00:00
(2/2): php-pecl-apcu-5.1.21-1.el7.remi.7.4.x86_64.rpm                                            |  76 kB  00:00:00
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   1.2 MB/s | 408 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php-opcache-7.4.29-1.el7.remi.x86_64                                                                 1/2
  Installing : php-pecl-apcu-5.1.21-1.el7.remi.7.4.x86_64                                                           2/2
  Verifying  : php-pecl-apcu-5.1.21-1.el7.remi.7.4.x86_64                                                           1/2
  Verifying  : php-opcache-7.4.29-1.el7.remi.x86_64                                                                 2/2
 
Installed:
  php-opcache.x86_64 0:7.4.29-1.el7.remi                  php-pecl-apcu.x86_64 0:5.1.21-1.el7.remi.7.4
 
Complete!

 

PHPへのインストール反映確認

php -v で「Zend OPcache」が入って入れば良さそう

php -v
PHP 7.4.29 (cli) (built: Apr 12 2022 10:55:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.29, Copyright (c), by Zend Technologies

サービス再起動

php-fpmが入っていれば

systemctrl restart php-fpm

 

apacheを再起動

systemctrl restart httpd

 

ngnxとか使えばもっと速くなるんでしょうが、取り合えず。。。

Tips

Posted by admin