そういうのがいいブログ

SIerで働く30代サラリーマンSEがインフラエンジニアに憧れてLinux・クラウド・AWSの勉強をするブログ

AlmaLinux 8のApache2環境にPHP 7.4をインストールする手順

※[PR]当ブログの記事の中にはプロモーションが含まれています。

・AlmaLinux 8 にPHP7.4をインストールする方法を知りたい。
・具体的な手順を分かりやすく教えてほしい。

こういった疑問に答えます。

本記事の内容

  1. AlmaLinux 8のApache2環境にPHP 7.4をインストールして使えるようにする手順

サトナカ (@souiunogaii)

この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。

こういった私が、解説していきます。

私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。

AlmaLinux 8のApache2環境にPHP 7.4をインストールして使えるようにする手順

前提(今回の環境)

OS Apache
AlmaLinux 8.8 2.4.37
[root@SV-ALTAIR ~]# cat /etc/redhat-release
AlmaLinux release 8.8 (Sapphire Caracal)
[root@SV-ALTAIR ~]# httpd -V | head -n 1
Server version: Apache/2.4.37 (AlmaLinux)

手順① PHPパッケージのインストール

dnf module install php:remi-7.4
[root@SV-ALTAIR ~]# dnf module install php:remi-7.4
メタデータの期限切れの最終確認: 0:04:05 前の 20230901193658秒 に実施しました。
依存関係が解決しました。
====================================================================================================
 パッケージ         Arch     バージョン                                        リポジトリー   サイズ
====================================================================================================
group/moduleパッケージをインストール:
 php-cli            x86_64   7.4.33-8.el8.remi                                 remi-modular   4.6 M
 php-common         x86_64   7.4.33-8.el8.remi                                 remi-modular   1.2 M
 php-fpm            x86_64   7.4.33-8.el8.remi                                 remi-modular   1.6 M
 php-mbstring       x86_64   7.4.33-8.el8.remi                                 remi-modular   530 k
 php-xml            x86_64   7.4.33-8.el8.remi                                 remi-modular   222 k
依存関係のインストール:
 oniguruma5php      x86_64   6.9.8-1.el8.remi                                  remi-safe      212 k
 php-json           x86_64   7.4.33-8.el8.remi                                 remi-modular    80 k
弱い依存関係のインストール:
 nginx-filesystem   noarch   1:1.14.1-9.module_el8.3.0+2165+af250afe.alma      appstream       23 k
モジュールプロファイルのインストール中:
 php/common
モジュールストリームの有効化中:
 php                         remi-7.4

トランザクションの概要
====================================================================================================
インストール  8 パッケージ

ダウンロードサイズの合計: 8.5 M
インストール後のサイズ: 41 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
(1/8): nginx-filesystem-1.14.1-9.module_el8.3.0+2165+af250afe.alma. 324 kB/s |  23 kB     00:00
(2/8): php-common-7.4.33-8.el8.remi.x86_64.rpm                      476 kB/s | 1.2 MB     00:02
(3/8): php-fpm-7.4.33-8.el8.remi.x86_64.rpm                         644 kB/s | 1.6 MB     00:02
(4/8): php-json-7.4.33-8.el8.remi.x86_64.rpm                        298 kB/s |  80 kB     00:00
(5/8): php-xml-7.4.33-8.el8.remi.x86_64.rpm                         780 kB/s | 222 kB     00:00
(6/8): php-mbstring-7.4.33-8.el8.remi.x86_64.rpm                    992 kB/s | 530 kB     00:00
(7/8): oniguruma5php-6.9.8-1.el8.remi.x86_64.rpm                    750 kB/s | 212 kB     00:00
(8/8): php-cli-7.4.33-8.el8.remi.x86_64.rpm                         1.0 MB/s | 4.6 MB     00:04
----------------------------------------------------------------------------------------------------
合計                                                                1.3 MB/s | 8.5 MB     00:06
Remi's Modular repository for Enterprise Linux 8 - x86_64           3.0 MB/s | 3.1 kB     00:00
GPG 鍵 0x5F11735A をインポート中:
 Userid     : "Remi's RPM repository <remi@remirepo.net>"
 Fingerprint: 6B38 FEA7 231F 87F5 2B9C A9D8 5550 9759 5F11 735A
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8
これでよろしいですか? [y/N]: y
鍵のインポートに成功しました
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                            1/1
  インストール中   : php-json-7.4.33-8.el8.remi.x86_64                                          1/8
  scriptletの実行中: php-common-7.4.33-8.el8.remi.x86_64                                        2/8
  インストール中   : php-common-7.4.33-8.el8.remi.x86_64                                        2/8
  インストール中   : oniguruma5php-6.9.8-1.el8.remi.x86_64                                      3/8
  scriptletの実行中: nginx-filesystem-1:1.14.1-9.module_el8.3.0+2165+af250afe.alma.noarch       4/8
  インストール中   : nginx-filesystem-1:1.14.1-9.module_el8.3.0+2165+af250afe.alma.noarch       4/8
  インストール中   : php-fpm-7.4.33-8.el8.remi.x86_64                                           5/8
  scriptletの実行中: php-fpm-7.4.33-8.el8.remi.x86_64                                           5/8
  インストール中   : php-mbstring-7.4.33-8.el8.remi.x86_64                                      6/8
  インストール中   : php-cli-7.4.33-8.el8.remi.x86_64                                           7/8
  インストール中   : php-xml-7.4.33-8.el8.remi.x86_64                                           8/8
  scriptletの実行中: php-common-7.4.33-8.el8.remi.x86_64                                        8/8
=====================================================================

  WARNING : PHP 7.4 have reached its "End of Life" in
  November 2022. Even, if this package includes some of
  the important security fixes, backported from 8.0, the
  UPGRADE to a maintained version is very strongly RECOMMENDED.

=====================================================================

  scriptletの実行中: php-xml-7.4.33-8.el8.remi.x86_64                                           8/8
  scriptletの実行中: php-fpm-7.4.33-8.el8.remi.x86_64                                           8/8
  検証             : nginx-filesystem-1:1.14.1-9.module_el8.3.0+2165+af250afe.alma.noarch       1/8
  検証             : php-cli-7.4.33-8.el8.remi.x86_64                                           2/8
  検証             : php-common-7.4.33-8.el8.remi.x86_64                                        3/8
  検証             : php-fpm-7.4.33-8.el8.remi.x86_64                                           4/8
  検証             : php-json-7.4.33-8.el8.remi.x86_64                                          5/8
  検証             : php-mbstring-7.4.33-8.el8.remi.x86_64                                      6/8
  検証             : php-xml-7.4.33-8.el8.remi.x86_64                                           7/8
  検証             : oniguruma5php-6.9.8-1.el8.remi.x86_64                                      8/8

インストール済み:
  nginx-filesystem-1:1.14.1-9.module_el8.3.0+2165+af250afe.alma.noarch
  oniguruma5php-6.9.8-1.el8.remi.x86_64
  php-cli-7.4.33-8.el8.remi.x86_64
  php-common-7.4.33-8.el8.remi.x86_64
  php-fpm-7.4.33-8.el8.remi.x86_64
  php-json-7.4.33-8.el8.remi.x86_64
  php-mbstring-7.4.33-8.el8.remi.x86_64
  php-xml-7.4.33-8.el8.remi.x86_64

完了しました!
dnf install php
[root@SV-ALTAIR ~]# dnf install php
メタデータの期限切れの最終確認: 0:04:50 前の 20230901193658秒 に実施しました。
依存関係が解決しました。
====================================================================================================
 パッケージ            アーキテクチャー バージョン                     リポジトリー           サイズ
====================================================================================================
インストール:
 php                   x86_64           7.4.33-8.el8.remi              remi-modular           3.0 M
依存関係のインストール:
 libsodium             x86_64           1.0.18-2.el8                   epel                   162 k
弱い依存関係のインストール:
 php-opcache           x86_64           7.4.33-8.el8.remi              remi-modular           340 k
 php-pdo               x86_64           7.4.33-8.el8.remi              remi-modular           147 k
 php-sodium            x86_64           7.4.33-8.el8.remi              remi-modular            93 k

トランザクションの概要
====================================================================================================
インストール  5 パッケージ

ダウンロードサイズの合計: 3.8 M
インストール後のサイズ: 11 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
(1/5): libsodium-1.0.18-2.el8.x86_64.rpm                            2.1 MB/s | 162 kB     00:00
(2/5): php-pdo-7.4.33-8.el8.remi.x86_64.rpm                         117 kB/s | 147 kB     00:01
(3/5): php-opcache-7.4.33-8.el8.remi.x86_64.rpm                     217 kB/s | 340 kB     00:01
(4/5): php-sodium-7.4.33-8.el8.remi.x86_64.rpm                      349 kB/s |  93 kB     00:00
(5/5): php-7.4.33-8.el8.remi.x86_64.rpm                             863 kB/s | 3.0 MB     00:03
----------------------------------------------------------------------------------------------------
合計                                                                788 kB/s | 3.8 MB     00:04
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                            1/1
  インストール中   : php-pdo-7.4.33-8.el8.remi.x86_64                                           1/5
  インストール中   : php-opcache-7.4.33-8.el8.remi.x86_64                                       2/5
  インストール中   : libsodium-1.0.18-2.el8.x86_64                                              3/5
  インストール中   : php-sodium-7.4.33-8.el8.remi.x86_64                                        4/5
  インストール中   : php-7.4.33-8.el8.remi.x86_64                                               5/5
  scriptletの実行中: php-7.4.33-8.el8.remi.x86_64                                               5/5
  検証             : libsodium-1.0.18-2.el8.x86_64                                              1/5
  検証             : php-7.4.33-8.el8.remi.x86_64                                               2/5
  検証             : php-opcache-7.4.33-8.el8.remi.x86_64                                       3/5
  検証             : php-pdo-7.4.33-8.el8.remi.x86_64                                           4/5
  検証             : php-sodium-7.4.33-8.el8.remi.x86_64                                        5/5

インストール済み:
  libsodium-1.0.18-2.el8.x86_64                      php-7.4.33-8.el8.remi.x86_64
  php-opcache-7.4.33-8.el8.remi.x86_64               php-pdo-7.4.33-8.el8.remi.x86_64
  php-sodium-7.4.33-8.el8.remi.x86_64

完了しました!
dnf install php-devel php-gd php-mysqlnd php-pdo php-pear php-xmlrpc  php-process
[root@SV-ALTAIR ~]# dnf install php-devel php-gd php-mysqlnd php-pdo php-pear php-xmlrpc  php-process
メタデータの期限切れの最終確認: 0:05:28 前の 20230901193658秒 に実施しました。
パッケージ php-pdo-7.4.33-8.el8.remi.x86_64 は既にインストールされています。
依存関係が解決しました。
====================================================================================================
 パッケージ                   Arch          バージョン                    リポジトリー        サイズ
====================================================================================================
インストール:
 php-devel                    x86_64        7.4.33-8.el8.remi             remi-modular        1.2 M
 php-gd                       x86_64        7.4.33-8.el8.remi             remi-modular         97 k
 php-mysqlnd                  x86_64        7.4.33-8.el8.remi             remi-modular        263 k
 php-pear                     noarch        1:1.10.13-5.el8.remi          remi-modular        366 k
 php-process                  x86_64        7.4.33-8.el8.remi             remi-modular        102 k
 php-xmlrpc                   x86_64        7.4.33-8.el8.remi             remi-modular         98 k
依存関係のインストール:
 cmake-filesystem             x86_64        3.20.2-5.el8                  appstream            44 k
 gd3php                       x86_64        2.3.3-8.el8.remi              remi-safe           148 k
 libaom                       x86_64        3.6.1-1.el8                   epel                1.9 M
 libavif                      x86_64        0.10.1-3.el8                  epel                 76 k
 libdav1d                     x86_64        0.5.2-2.el8                   epel                346 k
 libimagequant                x86_64        2.12.5-1.el8                  epel                 63 k
 libraqm                      x86_64        0.7.0-4.el8                   epel                 19 k
 libxml2-devel                x86_64        2.9.7-16.el8_8.1              appstream           1.0 M
 svt-av1-libs                 x86_64        0.8.7-1.el8                   epel                4.7 M
弱い依存関係のインストール:
 php-fedora-autoloader        noarch        1.0.1-2.el8.remi              remi-safe            13 k

トランザクションの概要
====================================================================================================
インストール  16 パッケージ

ダウンロードサイズの合計: 10 M
インストール後のサイズ: 39 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
(1/16): cmake-filesystem-3.20.2-5.el8.x86_64.rpm                    441 kB/s |  44 kB     00:00
(2/16): libxml2-devel-2.9.7-16.el8_8.1.x86_64.rpm                   3.4 MB/s | 1.0 MB     00:00
(3/16): libdav1d-0.5.2-2.el8.x86_64.rpm                             3.6 MB/s | 346 kB     00:00
(4/16): libimagequant-2.12.5-1.el8.x86_64.rpm                       3.0 MB/s |  63 kB     00:00
(5/16): libaom-3.6.1-1.el8.x86_64.rpm                               4.4 MB/s | 1.9 MB     00:00
(6/16): libavif-0.10.1-3.el8.x86_64.rpm                             219 kB/s |  76 kB     00:00
(7/16): libraqm-0.7.0-4.el8.x86_64.rpm                              570 kB/s |  19 kB     00:00
(8/16): svt-av1-libs-0.8.7-1.el8.x86_64.rpm                         5.6 MB/s | 4.7 MB     00:00
(9/16): php-gd-7.4.33-8.el8.remi.x86_64.rpm                          76 kB/s |  97 kB     00:01
(10/16): php-pear-1.10.13-5.el8.remi.noarch.rpm                     469 kB/s | 366 kB     00:00
(11/16): php-devel-7.4.33-8.el8.remi.x86_64.rpm                     513 kB/s | 1.2 MB     00:02
(12/16): php-process-7.4.33-8.el8.remi.x86_64.rpm                   377 kB/s | 102 kB     00:00
(13/16): php-mysqlnd-7.4.33-8.el8.remi.x86_64.rpm                   173 kB/s | 263 kB     00:01
(14/16): php-xmlrpc-7.4.33-8.el8.remi.x86_64.rpm                    367 kB/s |  98 kB     00:00
(15/16): php-fedora-autoloader-1.0.1-2.el8.remi.noarch.rpm           51 kB/s |  13 kB     00:00
(16/16): gd3php-2.3.3-8.el8.remi.x86_64.rpm                         530 kB/s | 148 kB     00:00
----------------------------------------------------------------------------------------------------
合計                                                                2.1 MB/s |  10 MB     00:04
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                            1/1
  インストール中   : php-fedora-autoloader-1.0.1-2.el8.remi.noarch                             1/16
  インストール中   : php-process-7.4.33-8.el8.remi.x86_64                                      2/16
  インストール中   : svt-av1-libs-0.8.7-1.el8.x86_64                                           3/16
  インストール中   : libraqm-0.7.0-4.el8.x86_64                                                4/16
  インストール中   : libimagequant-2.12.5-1.el8.x86_64                                         5/16
  インストール中   : libdav1d-0.5.2-2.el8.x86_64                                               6/16
  インストール中   : libaom-3.6.1-1.el8.x86_64                                                 7/16
  インストール中   : libavif-0.10.1-3.el8.x86_64                                               8/16
  インストール中   : gd3php-2.3.3-8.el8.remi.x86_64                                            9/16
  インストール中   : cmake-filesystem-3.20.2-5.el8.x86_64                                     10/16
  インストール中   : libxml2-devel-2.9.7-16.el8_8.1.x86_64                                    11/16
  インストール中   : php-devel-7.4.33-8.el8.remi.x86_64                                       12/16
  インストール中   : php-gd-7.4.33-8.el8.remi.x86_64                                          13/16
  インストール中   : php-pear-1:1.10.13-5.el8.remi.noarch                                     14/16
  インストール中   : php-xmlrpc-7.4.33-8.el8.remi.x86_64                                      15/16
  インストール中   : php-mysqlnd-7.4.33-8.el8.remi.x86_64                                     16/16
  scriptletの実行中: php-mysqlnd-7.4.33-8.el8.remi.x86_64                                     16/16
  検証             : cmake-filesystem-3.20.2-5.el8.x86_64                                      1/16
  検証             : libxml2-devel-2.9.7-16.el8_8.1.x86_64                                     2/16
  検証             : libaom-3.6.1-1.el8.x86_64                                                 3/16
  検証             : libavif-0.10.1-3.el8.x86_64                                               4/16
  検証             : libdav1d-0.5.2-2.el8.x86_64                                               5/16
  検証             : libimagequant-2.12.5-1.el8.x86_64                                         6/16
  検証             : libraqm-0.7.0-4.el8.x86_64                                                7/16
  検証             : svt-av1-libs-0.8.7-1.el8.x86_64                                           8/16
  検証             : php-devel-7.4.33-8.el8.remi.x86_64                                        9/16
  検証             : php-gd-7.4.33-8.el8.remi.x86_64                                          10/16
  検証             : php-mysqlnd-7.4.33-8.el8.remi.x86_64                                     11/16
  検証             : php-pear-1:1.10.13-5.el8.remi.noarch                                     12/16
  検証             : php-process-7.4.33-8.el8.remi.x86_64                                     13/16
  検証             : php-xmlrpc-7.4.33-8.el8.remi.x86_64                                      14/16
  検証             : gd3php-2.3.3-8.el8.remi.x86_64                                           15/16
  検証             : php-fedora-autoloader-1.0.1-2.el8.remi.noarch                            16/16

インストール済み:
  cmake-filesystem-3.20.2-5.el8.x86_64         gd3php-2.3.3-8.el8.remi.x86_64
  libaom-3.6.1-1.el8.x86_64                    libavif-0.10.1-3.el8.x86_64
  libdav1d-0.5.2-2.el8.x86_64                  libimagequant-2.12.5-1.el8.x86_64
  libraqm-0.7.0-4.el8.x86_64                   libxml2-devel-2.9.7-16.el8_8.1.x86_64
  php-devel-7.4.33-8.el8.remi.x86_64           php-fedora-autoloader-1.0.1-2.el8.remi.noarch
  php-gd-7.4.33-8.el8.remi.x86_64              php-mysqlnd-7.4.33-8.el8.remi.x86_64
  php-pear-1:1.10.13-5.el8.remi.noarch         php-process-7.4.33-8.el8.remi.x86_64
  php-xmlrpc-7.4.33-8.el8.remi.x86_64          svt-av1-libs-0.8.7-1.el8.x86_64

完了しました!

確認

php -v
[root@SV-ALTAIR ~]# php -v
PHP 7.4.33 (cli) (built: Aug  1 2023 08:47:49) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

手順② php-fpmの設定

dnf list installed | grep php-fpm
[root@SV-ALTAIR ~]# dnf list installed | grep php-fpm
php-fpm.x86_64                              7.4.33-8.el8.remi                            @remi-modular
vi /etc/php-fpm.d/www.conf

ユーザー、グループ

     20 ; Unix user/group of processes
     21 ; Note: The user is mandatory. If the group is not set, the default user's group
     22 ;       will be used.
     23 ; RPM: apache user chosen to provide access to the same directories as httpd
     24 user = www  ←★★変更
     25 ; RPM: Keep a group allowed to write in log dir.
     26 group = www  ←★★変更
     44 ; Set permissions for unix socket, if one is used. In Linux, read/write
     45 ; permissions must be set in order to allow connections from a web server.
     46 ; Default Values: user and group are set as the running user
     47 ;                 mode is set to 0660
     48 listen.owner = www  ←★★変更
     49 listen.group = www  ←★★変更
     50 listen.mode = 0666  ←★★変更

子プロセスの最大数

    106 ; The number of child processes to be created when pm is set to 'static' and the
    107 ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
    108 ; This value sets the limit on the number of simultaneous requests that will be
    109 ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
    110 ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
    111 ; CGI. The below defaults are based on a server without much resources. Don't
    112 ; forget to tweak pm.* to fit your needs.
    113 ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
    114 ; Note: This value is mandatory.
    115 pm.max_children = 25  ←★★変更

サービス開始時に起動される子プロセスの数

    117 ; The number of child processes created on startup.
    118 ; Note: Used only when pm is set to 'dynamic'
    119 ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    120 pm.start_servers = 10  ←★★変更

待ち状態になる子プロセスの最小の数値

    122 ; The desired minimum number of idle server processes.
    123 ; Note: Used only when pm is set to 'dynamic'
    124 ; Note: Mandatory when pm is set to 'dynamic'
    125 pm.min_spare_servers = 10  ←★★変更

待ち状態になる子プロセスの最大の数値

    127 ; The desired maximum number of idle server processes.
    128 ; Note: Used only when pm is set to 'dynamic'
    129 ; Note: Mandatory when pm is set to 'dynamic'
    130 pm.max_spare_servers = 20  ←★★変更

子プロセスが再起動するまでに実行するリクエスト数

    132 ; The number of seconds after which an idle process will be killed.
    133 ; Note: Used only when pm is set to 'ondemand'
    134 ; Default Value: 10s
    135 ;pm.process_idle_timeout = 10s;
    136
    137 ; The number of requests each child process should execute before respawning.
    138 ; This can be useful to work around memory leaks in 3rd party libraries. For
    139 ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
    140 ; Default Value: 0
    141 pm.max_requests = 500  ←★★変更

再起動して設定を反映

systemctl start php-fpm
systemctl status php-fpm
[root@SV-ALTAIR ~]# systemctl start php-fpm
[root@SV-ALTAIR ~]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2023-09-01 19:49:53 JST; 6s ago
 Main PID: 4448 (php-fpm)
   Status: "Ready to handle connections"
    Tasks: 11 (limit: 24824)
   Memory: 20.6M
   CGroup: /system.slice/php-fpm.service
           tq4448 php-fpm: master process (/etc/php-fpm.conf)
           tq4449 php-fpm: pool www
           tq4450 php-fpm: pool www
           tq4451 php-fpm: pool www
           tq4452 php-fpm: pool www
           tq4453 php-fpm: pool www
           tq4454 php-fpm: pool www
           tq4455 php-fpm: pool www
           tq4456 php-fpm: pool www
           tq4457 php-fpm: pool www
           mq4458 php-fpm: pool www

 901 19:49:53 SV-ALTAIR systemd[1]: Starting The PHP FastCGI Process Manager...
 901 19:49:53 SV-ALTAIR php-fpm[4448]: [01-Sep-2023 19:49:53] WARNING: [pool www] ACL set, liste>
 901 19:49:53 SV-ALTAIR php-fpm[4448]: [01-Sep-2023 19:49:53] WARNING: [pool www] ACL set, liste>
 901 19:49:53 SV-ALTAIR systemd[1]: Started The PHP FastCGI Process Manager.

自動起動の設定

systemctl enable php-fpm
systemctl is-enabled php-fpm
[root@SV-ALTAIR ~]# systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@SV-ALTAIR ~]# systemctl is-enabled php-fpm
enabled

手順③ php.iniの設定変更

vi /etc/php.ini

PHPのバージョンを非表示にする

    374 ; Decides whether PHP may expose the fact that it is installed on the server
    375 ; (e.g. by adding its signature to the Web server header).  It is no security
    376 ; threat in any way, but it makes it possible to determine whether you use PHP
    377 ; on your server or not.
    378 ; http://php.net/expose-php
    379 expose_php = Off  ←★★変更

アップロードするデータの最大サイズ

    690 ; Maximum size of POST data that PHP will accept.
    691 ; Its value may be 0 to disable the limit. It is ignored if POST data reading
    692 ; is disabled through enable_post_data_reading.
    693 ; http://php.net/post-max-size
    694 post_max_size = 20M ←★★変更
    844 ; Maximum allowed size for uploaded files.
    845 ; http://php.net/upload-max-filesize
    846 upload_max_filesize = 20M ←★★変更

タイムゾーン

    921 ; Defines the default timezone used by the date functions
    922 ; http://php.net/date.timezone
    923 date.timezone = "Asia/Tokyo" ←★★変更

日本語の2バイト文字対応

   1498 [mbstring]
   1499 ; language for internal character representation.
   1500 ; This affects mb_send_mail() and mbstring.detect_order.
   1501 ; http://php.net/mbstring.language
   1502 mbstring.language = Japanese ←★★変更
   1504 ; Use of this INI entry is deprecated, use global internal_encoding instead.
   1505 ; internal/script encoding.
   1506 ; Some encoding cannot work as internal encoding. (e.g. SJIS, BIG5, ISO-2022-*)
   1507 ; If empty, default_charset or internal_encoding or iconv.internal_encoding is used.
   1508 ; The precedence is: default_charset < internal_encoding < iconv.internal_encoding
   1509 mbstring.internal_encoding = UTF-8 ←★★変更
   1511 ; Use of this INI entry is deprecated, use global input_encoding instead.
   1512 ; http input encoding.
   1513 ; mbstring.encoding_translation = On is needed to use this setting.
   1514 ; If empty, default_charset or input_encoding or mbstring.input is used.
   1515 ; The precedence is: default_charset < input_encoding < mbsting.http_input
   1516 ; http://php.net/mbstring.http-input
   1517 mbstring.http_input = UTF-8 ←★★変更
   1519 ; Use of this INI entry is deprecated, use global output_encoding instead.
   1520 ; http output encoding.
   1521 ; mb_output_handler must be registered as output buffer to function.
   1522 ; If empty, default_charset or output_encoding or mbstring.http_output is used.
   1523 ; The precedence is: default_charset < output_encoding < mbstring.http_output
   1524 ; To use an output encoding conversion, mbstring's output handler must be set
   1525 ; otherwise output encoding conversion cannot be performed.
   1526 ; http://php.net/mbstring.http-output
   1527 mbstring.http_output = pass ←★★変更
   1529 ; enable automatic encoding translation according to
   1530 ; mbstring.internal_encoding setting. Input chars are
   1531 ; converted to internal encoding by setting this to On.
   1532 ; Note: Do _not_ use automatic encoding translation for
   1533 ;       portable libs/applications.
   1534 ; http://php.net/mbstring.encoding-translation
   1535 mbstring.encoding_translation = On ←★★変更
   1537 ; automatic encoding detection order.
   1538 ; "auto" detect order is changed according to mbstring.language
   1539 ; http://php.net/mbstring.detect-order
   1540 mbstring.detect_order = auto ←★★変更
   1542 ; substitute_character used when character cannot be converted
   1543 ; one from another
   1544 ; http://php.net/mbstring.substitute-character
   1545 mbstring.substitute_character = none ←★★変更

再起動して設定を反映

systemctl restart php-fpm
systemctl status php-fpm
[root@SV-ALTAIR ~]# systemctl restart php-fpm
[root@SV-ALTAIR ~]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2023-09-01 19:57:30 JST; 8s ago
 Main PID: 4520 (php-fpm)
   Status: "Ready to handle connections"
    Tasks: 11 (limit: 24824)
   Memory: 20.5M
   CGroup: /system.slice/php-fpm.service
           tq4520 php-fpm: master process (/etc/php-fpm.conf)
           tq4522 php-fpm: pool www
           tq4523 php-fpm: pool www
           tq4524 php-fpm: pool www
           tq4525 php-fpm: pool www
           tq4526 php-fpm: pool www
           tq4527 php-fpm: pool www
           tq4528 php-fpm: pool www
           tq4529 php-fpm: pool www
           tq4530 php-fpm: pool www
           mq4531 php-fpm: pool www

 901 19:57:30 SV-ALTAIR systemd[1]: php-fpm.service: Succeeded.
 901 19:57:30 SV-ALTAIR systemd[1]: Stopped The PHP FastCGI Process Manager.
 901 19:57:30 SV-ALTAIR systemd[1]: Starting The PHP FastCGI Process Manager...
 901 19:57:30 SV-ALTAIR php-fpm[4520]: [01-Sep-2023 19:57:30] WARNING: [pool www] ACL set, liste>
 901 19:57:30 SV-ALTAIR php-fpm[4520]: [01-Sep-2023 19:57:30] WARNING: [pool www] ACL set, liste>
 901 19:57:30 SV-ALTAIR systemd[1]: Started The PHP FastCGI Process Manager.
systemctl restart httpd
systemctl status httpd
[root@SV-ALTAIR~]# systemctl restart httpd
[root@SV-ALTAIR ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/httpd.service.d
           mqphp-fpm.conf
   Active: active (running) since Fri 2023-09-01 19:57:57 JST; 5s ago
     Docs: man:httpd.service(8)
 Main PID: 4541 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 213 (limit: 24824)
   Memory: 31.1M
   CGroup: /system.slice/httpd.service
           tq4541 /usr/sbin/httpd -DFOREGROUND
           tq4543 /usr/sbin/httpd -DFOREGROUND
           tq4544 /usr/sbin/httpd -DFOREGROUND
           tq4545 /usr/sbin/httpd -DFOREGROUND
           mq4546 /usr/sbin/httpd -DFOREGROUND

 901 19:57:57 SV-ALTAIR systemd[1]: httpd.service: Succeeded.
 901 19:57:57 SV-ALTAIR systemd[1]: Stopped The Apache HTTP Server.
 901 19:57:57 SV-ALTAIR systemd[1]: Starting The Apache HTTP Server...
 901 19:57:57 SV-ALTAIR systemd[1]: Started The Apache HTTP Server.
 901 19:57:57 SV-ALTAIR httpd[4541]: Server configured, listening on: port 80

手順④ 動作確認

php -r 'phpinfo();
[root@SV-ALTAIR ~]# php -r 'phpinfo();'
phpinfo()
PHP Version => 7.4.33

System => Linux SV-ALTAIR 4.18.0-477.21.1.el8_8.x86_64 #1 SMP Thu Aug 10 13:51:50 EDT 2023 x86_64
Build Date => Aug  1 2023 08:47:49
Build System => Red Hat Enterprise Linux release 8.8 (Ootpa)
Build Provider => Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
Scan this dir for additional .ini files => /etc/php.d
Additional .ini files parsed => /etc/php.d/10-opcache.ini,

==========中略=========


PHP License
This program is free software; you can redistribute it and/or modify
it under the terms of the PHP License as published by the PHP Group
and included in the distribution in the file:  LICENSE

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you did not receive a copy of the PHP license, or have any
questions about PHP licensing, please contact license@php.net.
vi /home/www/html/test01/test.php
<?php phpinfo(); ?>