以下の内容はhttps://souiunogaii.hatenablog.com/entry/almalinux96-php84-installより取得しました。


AlmaLinux9.6+Apache2.4環境にPHP8.4をインストールする手順

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

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

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

本記事の内容

  1. AlmaLinux9.6+Apache2.4環境にPHP8.4をインストールする手順

サトナカ (@souiunogaii)

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

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

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

AlmaLinux9.6+Apache2.4環境にPHP8.4をインストールする手順

環境の確認

[root@a-webap01 ~]# cat /etc/redhat-release
AlmaLinux release 9.6 (Sage Margay)
[root@a-webap01 ~]# httpd -V | head -n 1
Server version: Apache/2.4.62 (AlmaLinux)

remiリポジトリのインストール

事前確認

[root@a-webap01 ~]# dnf module list php
メタデータの期限切れの最終確認: 0:49:05 前の 20250901172540秒 に実施しました。
AlmaLinux 9 - AppStream
Name           Stream           Profiles                             Summary
php            8.1              common [d], devel, minimal           PHP scripting language
php            8.2              common [d], devel, minimal           PHP scripting language
php            8.3              common [d], devel, minimal           PHP scripting language

ヒント: [d]efault, [e]nabled, [x]disabled, [i]nstalled

標準では8.3までしか提供されていません。

remiインストール

dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
[root@a-webap01 ~]# dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
メタデータの期限切れの最終確認: 0:51:39 前の 20250901172540秒 に実施しました。
remi-release-9.rpm                                                   27 kB/s |  32 kB     00:01
依存関係が解決しました。
====================================================================================================
 パッケージ              アーキテクチャー  バージョン                 リポジトリー            サイズ
====================================================================================================
インストール:
 remi-release            noarch            9.5-2.el9.remi             @commandline             32 k
依存関係のインストール:
 epel-release            noarch            9-9.el9                    extras                   18 k

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

合計サイズ: 51 k
ダウンロードサイズの合計: 18 k
インストール後のサイズ: 60 k
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
epel-release-9-9.el9.noarch.rpm                                     226 kB/s |  18 kB     00:00
----------------------------------------------------------------------------------------------------
合計                                                                 25 kB/s |  18 kB     00:00
トランザクションを確認しています
トランザクションの確認に成功しました。
トランザクションをテストしています
トランザクションのテストに成功しました。
トランザクションを実行しています
  準備中           :                                                                            1/1
  インストール中   : epel-release-9-9.el9.noarch                                                1/2
  scriptletの実行中: epel-release-9-9.el9.noarch                                                1/2
Many EPEL packages require the CodeReady Builder (CRB) repository.
It is recommended that you run /usr/bin/crb enable to enable the CRB repository.

  インストール中   : remi-release-9.5-2.el9.remi.noarch                                         2/2
  scriptletの実行中: remi-release-9.5-2.el9.remi.noarch                                         2/2
  検証中           : epel-release-9-9.el9.noarch                                                1/2
  検証中           : remi-release-9.5-2.el9.remi.noarch                                         2/2

インストール済み:
  epel-release-9-9.el9.noarch                   remi-release-9.5-2.el9.remi.noarch

完了しました!

再度,確認

dnf config-manager --set-enabled remi
dnf module list php
[root@a-webap01 ~]# dnf config-manager --set-enabled remi
[root@a-webap01 ~]# dnf module list php
Extra Packages for Enterprise Linux 9 - x86_64                      5.2 MB/s |  20 MB     00:03
Extra Packages for Enterprise Linux 9 openh264 (From Cisco) - x86_6 1.5 kB/s | 2.5 kB     00:01
Remi's RPM repository for Enterprise Linux 9 - x86_64               448 kB/s | 2.3 MB     00:05
Remi's Modular repository for Enterprise Linux 9 - x86_64           294 kB/s | 833 kB     00:02
Safe Remi's RPM repository for Enterprise Linux 9 - x86_64          400 kB/s | 1.3 MB     00:03
メタデータの期限切れの最終確認: 0:00:01 前の 2025年09月01日 18時18分51秒 に実施しました。
AlmaLinux 9 - AppStream
Name           Stream            Profiles                            Summary
php            8.1               common [d], devel, minimal          PHP scripting language
php            8.2               common [d], devel, minimal          PHP scripting language
php            8.3               common [d], devel, minimal          PHP scripting language

Remi's Modular repository for Enterprise Linux 9 - x86_64
Name           Stream            Profiles                            Summary
php            remi-7.4          common [d], devel, minimal          PHP scripting language
php            remi-8.0          common [d], devel, minimal          PHP scripting language
php            remi-8.1          common [d], devel, minimal          PHP scripting language
php            remi-8.2          common [d], devel, minimal          PHP scripting language
php            remi-8.3          common [d], devel, minimal          PHP scripting language
php            remi-8.4          common [d], devel, minimal          PHP scripting language

ヒント: [d]efault, [e]nabled, [x]disabled, [i]nstalled

最新8.4がリストの表示されましたので有効化します。

[root@a-webap01 ~]# dnf module enable php:remi-8.4
メタデータの期限切れの最終確認: 0:00:43 前の 20250901181851秒 に実施しました。
依存関係が解決しました。
====================================================================================================
 パッケージ             アーキテクチャー      バージョン               リポジトリー           サイズ
====================================================================================================
モジュールストリームの有効化中:
 php                                          remi-8.4

トランザクションの概要
====================================================================================================

これでよろしいですか? [y/N]: y
完了しました!

PHP8.4インストール

dnf install php
[root@a-webap01 ~]# dnf install php
メタデータの期限切れの最終確認: 0:01:10 前の 20250901181851秒 に実施しました。
依存関係が解決しました。
====================================================================================================
 パッケージ              Arch          バージョン                         リポジトリー        サイズ
====================================================================================================
インストール:
 php                     x86_64        8.4.12-1.el9.remi                  remi-modular        1.9 M
依存関係のインストール:
 capstone                x86_64        4.0.2-10.el9                       appstream           766 k
 libsodium               x86_64        1.0.18-8.el9                       epel                161 k
 oniguruma5php           x86_64        6.9.10-1.el9.remi                  remi                222 k
 php-common              x86_64        8.4.12-1.el9.remi                  remi-modular        755 k
弱い依存関係のインストール:
 nginx-filesystem        noarch        2:1.20.1-22.el9_6.3.alma.1         appstream           9.5 k
 php-cli                 x86_64        8.4.12-1.el9.remi                  remi-modular        3.9 M
 php-fpm                 x86_64        8.4.12-1.el9.remi                  remi-modular        2.0 M
 php-mbstring            x86_64        8.4.12-1.el9.remi                  remi-modular        536 k
 php-opcache             x86_64        8.4.12-1.el9.remi                  remi-modular        500 k
 php-pdo                 x86_64        8.4.12-1.el9.remi                  remi-modular         96 k
 php-sodium              x86_64        8.4.12-1.el9.remi                  remi-modular         43 k
 php-xml                 x86_64        8.4.12-1.el9.remi                  remi-modular        957 k

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

ダウンロードサイズの合計: 12 M
インストール後のサイズ: 58 M
これでよろしいですか? [y/N]: y

追加パッケージのインストール

dnf install php-devel php-gd php-mysqlnd php-pdo php-pear php-xmlrpc  php-process
[root@a-webap01 ~]# dnf install php-devel php-gd php-mysqlnd php-pdo php-pear php-xmlrpc  php-process
メタデータの期限切れの最終確認: 0:03:06 前の 20250901181851秒 に実施しました。
パッケージ php-pdo-8.4.12-1.el9.remi.x86_64 は既にインストールされています。
依存関係が解決しました。
====================================================================================================
 パッケージ                  Arch         バージョン                       リポジトリー       サイズ
====================================================================================================
インストール:
 php-devel                   x86_64       8.4.12-1.el9.remi                remi-modular       782 k
 php-gd                      x86_64       8.4.12-1.el9.remi                remi-modular        53 k
 php-mysqlnd                 x86_64       8.4.12-1.el9.remi                remi-modular       152 k
 php-pear                    noarch       1:1.10.16-2.el9.remi             remi               311 k
 php-pecl-xmlrpc             x86_64       1.0.0~rc3-10.el9.remi.8.4        remi-modular        53 k
 php-process                 x86_64       8.4.12-1.el9.remi                remi-modular        48 k

確認

[root@a-webap01 ~]# php -v
PHP 8.4.12 (cli) (built: Aug 26 2025 13:36:28) (NTS gcc x86_64)
Copyright (c) The PHP Group
Built by Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine
Zend Engine v4.4.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.12, Copyright (c), by Zend Technologies
[root@a-webap01 ~]# dnf list installed | grep php-fpm
php-fpm.x86_64                                 8.4.12-1.el9.remi                @remi-modular

php-fpmの設定

/etc/php-fpm.d/www.conf
     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 = apache
     49 listen.group = apache
     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   ←★★★変更
    116
    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   ←★★★変更
    121
    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   ←★★★変更
    126
    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   ←★★★変更
    131
    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   ←★★★変更

php-fpmサービス起動

[root@a-webap01 ~]# systemctl start php-fpm

自動起動の設定

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

php.iniの設定変更

/etc/php.ini
    391 ;;;;;;;;;;;;;;;;;
    392 ; Miscellaneous ;
    393 ;;;;;;;;;;;;;;;;;
    394
    395 ; Decides whether PHP may expose the fact that it is installed on the server
    396 ; (e.g. by adding its signature to the Web server header).  It is no security
    397 ; threat in any way, but it makes it possible to determine whether you use PHP
    398 ; on your server or not.
    399 ; https://php.net/expose-php
    400 expose_php = Off  ←★★★変更

  (中略)

    699 ; Maximum size of POST data that PHP will accept.
    700 ; Its value may be 0 to disable the limit. It is ignored if POST data reading
    701 ; is disabled through enable_post_data_reading.
    702 ; https://php.net/post-max-size
    703 post_max_size = 20M  ←★★★変更

  (中略)

    853 ; Maximum allowed size for uploaded files.
    854 ; https://php.net/upload-max-filesize
    855 upload_max_filesize = 20M  ←★★★変更


  (中略)

    929 [Date]
    930 ; Defines the default timezone used by the date functions
    931 ; https://php.net/date.timezone
    932 date.timezone = "Asia/Tokyo"  ←★★★変更


  (中略)


   1467 [mbstring]
   1468 ; language for internal character representation.
   1469 ; This affects mb_send_mail() and mbstring.detect_order.
   1470 ; https://php.net/mbstring.language
   1471 mbstring.language = Japanese  ←★★★変更
   1472
   1473 ; Use of this INI entry is deprecated, use global internal_encoding instead.
   1474 ; internal/script encoding.
   1475 ; Some encoding cannot work as internal encoding. (e.g. SJIS, BIG5, ISO-2022-*)
   1476 ; If empty, default_charset or internal_encoding or iconv.internal_encoding is used.
   1477 ; The precedence is: default_charset < internal_encoding < iconv.internal_encoding
   1478 mbstring.internal_encoding = UTF-8  ←★★★変更
   1479
   1480 ; Use of this INI entry is deprecated, use global input_encoding instead.
   1481 ; http input encoding.
   1482 ; mbstring.encoding_translation = On is needed to use this setting.
   1483 ; If empty, default_charset or input_encoding or mbstring.input is used.
   1484 ; The precedence is: default_charset < input_encoding < mbstring.http_input
   1485 ; https://php.net/mbstring.http-input
   1486 mbstring.http_input = UTF-8  ←★★★変更
   1487
   1488 ; Use of this INI entry is deprecated, use global output_encoding instead.
   1489 ; http output encoding.
   1490 ; mb_output_handler must be registered as output buffer to function.
   1491 ; If empty, default_charset or output_encoding or mbstring.http_output is used.
   1492 ; The precedence is: default_charset < output_encoding < mbstring.http_output
   1493 ; To use an output encoding conversion, mbstring's output handler must be set
   1494 ; otherwise output encoding conversion cannot be performed.
   1495 ; https://php.net/mbstring.http-output
   1496 mbstring.http_output = pass  ←★★★変更
   1497
   1498 ; enable automatic encoding translation according to
   1499 ; mbstring.internal_encoding setting. Input chars are
   1500 ; converted to internal encoding by setting this to On.
   1501 ; Note: Do _not_ use automatic encoding translation for
   1502 ;       portable libs/applications.
   1503 ; https://php.net/mbstring.encoding-translation
   1504 mbstring.encoding_translation = On  ←★★★変更
   1505
   1506 ; automatic encoding detection order.
   1507 ; "auto" detect order is changed according to mbstring.language
   1508 ; https://php.net/mbstring.detect-order
   1509 mbstring.detect_order = auto  ←★★★変更
   1510
   1511 ; substitute_character used when character cannot be converted
   1512 ; one from another
   1513 ; https://php.net/mbstring.substitute-character
   1514 mbstring.substitute_character = none  ←★★★変更

再起動して設定を反映

[root@a-webap01 ~]# systemctl restart php-fpm
[root@a-webap01 ~]# systemctl restart httpd

動作確認

[root@a-webap01 ~]# php -r 'phpinfo();'
phpinfo()
PHP Version => 8.4.12


  (以下略)

テストページ作成

/home/www/html/test01/test.php
<?php phpinfo(); ?>




以上の内容はhttps://souiunogaii.hatenablog.com/entry/almalinux96-php84-installより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14