0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSLのAlma Linux 9 でPHP 8.2 ( CGI ) をインストールする

Posted at

概要

  • Webサーバーで動かす目的ではないため、CGI版をインストールしました。

  • php-cliを使用し、WSL上のシェルでPHPスクリプトを実行できるようにします。

PS C:\WINDOWS\system32> wsl -d AlmaLinux-9

[web-setest@Ataraxia system32]$ cat /etc/redhat-release
AlmaLinux release 9.5 (Teal Serval)

# 利用可能な PHP モジュールの一覧
dnf module list php
AlmaLinux 9 - AppStream                                                                 6.0 kB/s | 4.2 kB     00:00
AlmaLinux 9 - AppStream                                                                  13 MB/s |  13 MB     00:00
AlmaLinux 9 - BaseOS                                                                    5.7 kB/s | 3.8 kB     00:00
AlmaLinux 9 - BaseOS                                                                     12 MB/s |  12 MB     00:00
AlmaLinux 9 - Extras                                                                    6.0 kB/s | 3.8 kB     00:00
AlmaLinux 9 - Extras                                                                     29 kB/s |  20 kB     00:00
Last metadata expiration check: 0:00:01 ago on Fri 11 Jul 2025 12:02:08 PM JST.
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

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

# common, devel, minimal というプロファイルはそれぞれ、どんなパッケージを含むの?ってことを調べる
dnf module info php:8.2 --profile
Last metadata expiration check: 0:03:35 ago on Fri 11 Jul 2025 12:02:08 PM JST.
Name    : php:8.2:9060020250513151325:8cf767d6:x86_64
common  : php-cli
        : php-common
        : php-fpm
        : php-mbstring
        : php-xml
devel   : php-cli
        : php-common
        : php-devel
        : php-fpm
        : php-mbstring
        : php-pecl-zip
        : php-process
        : php-xml
minimal : php-cli
        : php-common

# 最小構成 (minimal) をインストール
sudo dnf module -y install php:8.2/minimal
[sudo] password for web-setest:
AlmaLinux 9 - AppStream                                                           6.2 kB/s | 4.2 kB     00:00
AlmaLinux 9 - BaseOS                                                              5.9 kB/s | 3.8 kB     00:00
AlmaLinux 9 - Extras                                                              6.0 kB/s | 3.8 kB     00:00
Dependencies resolved.
==================================================================================================================
 Package              Architecture     Version                                          Repository           Size
==================================================================================================================
Installing group/module packages:
 php-cli              x86_64           8.2.28-1.module_el9.6.0+165+cf879a7c             appstream           3.6 M
 php-common           x86_64           8.2.28-1.module_el9.6.0+165+cf879a7c             appstream           708 k
Installing module profiles:
 php/minimal
Enabling module streams:
 php                                   8.2

Transaction Summary
==================================================================================================================
Install  2 Packages

Total download size: 4.3 M
Installed size: 24 M
Downloading Packages:
(1/2): php-common-8.2.28-1.module_el9.6.0+165+cf879a7c.x86_64.rpm                 7.2 MB/s | 708 kB     00:00
(2/2): php-cli-8.2.28-1.module_el9.6.0+165+cf879a7c.x86_64.rpm                     23 MB/s | 3.6 MB     00:00
------------------------------------------------------------------------------------------------------------------
Total                                                                             5.2 MB/s | 4.3 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                          1/1
  Installing       : php-common-8.2.28-1.module_el9.6.0+165+cf879a7c.x86_64                                   1/2
warning: Unable to get systemd shutdown inhibition lock: Could not activate remote peer.

  Installing       : php-cli-8.2.28-1.module_el9.6.0+165+cf879a7c.x86_64                                      2/2
  Running scriptlet: php-cli-8.2.28-1.module_el9.6.0+165+cf879a7c.x86_64                                      2/2
  Verifying        : php-cli-8.2.28-1.module_el9.6.0+165+cf879a7c.x86_64                                      1/2
  Verifying        : php-common-8.2.28-1.module_el9.6.0+165+cf879a7c.x86_64                                   2/2

Installed:
  php-cli-8.2.28-1.module_el9.6.0+165+cf879a7c.x86_64    php-common-8.2.28-1.module_el9.6.0+165+cf879a7c.x86_64

Complete!

# インストールの確認
php -v
PHP 8.2.28 (cli) (built: Mar 11 2025 17:58:12) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.28, Copyright (c) Zend Technologies

参考

補足
ChatGPT による回答より↓

モジュール 必要性 用途・補足
php-fpm ❌ 不要 Web サーバーと連携する FastCGI 実行環境。CLI 実行には不要。
php-mbstring ⭕ 条件付き マルチバイト文字(日本語など)を扱う場合に必要。レスポンス等が UTF-8 で日本語を含むなら推奨。
php-xml ⭕ 条件付き XML をパース・生成する場合に必要。たとえば API が XML 形式なら必須。JSON 形式なら不要。

※今回は REST API (JSON 形式でリクエストを投げるWordPress REST API ) をテスト的に叩きたいだけだったので、インストール時には php-mbstringphp-xml モジュールはインストールしませんでした。本のタイトル、ブログの投稿内容を取得するなど、日本語がレスポンスとして返ってくるなら、適宜 php-mbstring もインストールしてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?