M1 MacにUTMを使ってウェブ開発(LAMP)環境を構築する 【3】(PHP8 ・Apache2.4)

開発環境

さて、何から行きましょうかね?

PHPのインストール

とりま現状確認

まずはデフォで入ってないか確認して、標準リポジトリだとどのバージョンが入るかも確認。

 $ dnf list installed | grep php
 $
 # デフォでは入ってないようだ

 $ dnf info php
Last metadata expiration check: 0:01:04 ago on Mon Dec 30 20:59:31 2024.
Available Packages
Name         : php
Version      : 8.0.30
Release      : 1.el9_2
Architecture : aarch64
Size         : 7.7 k
Source       : php-8.0.30-1.el9_2.src.rpm
Repository   : appstream
Summary      : PHP scripting language for creating dynamic web sites
URL          : http://www.php.net/
License      : PHP and Zend and BSD and MIT and ASL 1.0 and NCSA
Description  : PHP is an HTML-embedded scripting language. PHP attempts to make it
             : easy for developers to write dynamically generated web pages. PHP also
             : offers built-in database integration for several commercial and
             : non-commercial database management systems, so writing a
             : database-enabled webpage with PHP is fairly simple. The most common
             : use of PHP coding is probably as a replacement for CGI scripts.

うん、古い。
やっぱりPHPといえばremiですかね。

remiを使う準備

最新の情報を漁ってたら、こんな記事を見つけた。
dnf にEPELリポジトリを追加する Rocky Linux 8, 9

Rocky Linux 9の場合は、crbリポジトリ(CodeReady Builderリポジトリ)を有効にしておくことが推奨されています。

だそうな。よく知らんので言われるがままに

$ sudo dnf config-manager --set-enabled crb

# で、EPELは既にインストールしてあるので、remiをインストールする
$  sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Rocky Linux 9 - BaseOS                                                                                     4.4 kB/s | 4.1 kB     00:00    
Rocky Linux 9 - AppStream                                                                                  5.9 kB/s | 4.5 kB     00:00    
Rocky Linux 9 - CRB                                                                                        6.3 kB/s | 4.5 kB     00:00    
remi-release-9.rpm                                                                                          20 kB/s |  30 kB     00:01    
Dependencies resolved.
===========================================================================================================================================
 Package                           Architecture                Version                             Repository                         Size
===========================================================================================================================================
Installing:
 remi-release                      noarch                      9.5-1.el9.remi                      @commandline                       30 k

Transaction Summary
===========================================================================================================================================
Install  1 Package

Total size: 30 k
Installed size: 31 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                   1/1 
  Installing       : remi-release-9.5-1.el9.remi.noarch                                                                                1/1 
  Verifying        : remi-release-9.5-1.el9.remi.noarch                                                                                1/1 

Installed:
  remi-release-9.5-1.el9.remi.noarch                                                                                                       

Complete!

# remiを有効にする
$ sudo dnf config-manager --enable remi

#remiリポジトリがちゃんと追加されてることを確認
# 以下3つが追加されたぜ
$ dnf repolist 
remi                                         Remi’s RPM repository for Enterprise Linux 9 - aarch64
remi-modular                                 Remi’s Modular repository for Enterprise Linux 9 - aarch64
remi-safe                                    Safe Remi’s RPM repository for Enterprise Linux 9 - aarch64

# とりあえずAvailableなパッケージを調べる

$ dnf list php*

# remiでPHP8.4がインストールできることがわかったのでそれでいきましょ

PHP8.4をインストール

dnfのメリットらしいのだが、PHPをパッケージ版・モジュール版を選んでインストールできるようだ。PHPだけでなく、Apacheなどもモジュールでインストールできるらしい。いいかも。

# remiを指定してモジュールをインストール

$ sudo dnf module install php:remi-8.3
[sudo] password for yngdrsk: 
Remi’s RPM repository for Enterprise Linux 9 - aarch64                                                     132 kB/s | 1.7 MB     00:12    
Remi’s Modular repository for Enterprise Linux 9 - aarch64                                                  75 kB/s | 678 kB     00:09    
Safe Remi’s RPM repository for Enterprise Linux 9 - aarch64                                                 95 kB/s | 1.0 MB     00:11    
Last metadata expiration check: 0:00:07 ago on Mon Dec 30 21:32:58 2024.
Dependencies resolved.
===========================================================================================================================================
 Package                            Architecture              Version                                 Repository                      Size
===========================================================================================================================================
Installing group/module packages:
 php-cli                            aarch64                   8.3.15-1.el9.remi                       remi-modular                   2.3 M
 php-common                         aarch64                   8.3.15-1.el9.remi                       remi-modular                   702 k
 php-fpm                            aarch64                   8.3.15-1.el9.remi                       remi-modular                   1.9 M
 php-mbstring                       aarch64                   8.3.15-1.el9.remi                       remi-modular                   519 k
 php-xml                            aarch64                   8.3.15-1.el9.remi                       remi-modular                   150 k
Installing dependencies:
 httpd-filesystem                   noarch                    2.4.62-1.el9                            appstream                       12 k
 oniguruma5php                      aarch64                   6.9.9-2.el9.remi                        remi                           213 k
Installing weak dependencies:
 nginx-filesystem                   noarch                    2:1.20.1-20.el9.0.1                     appstream                      8.4 k
Installing module profiles:
 php/common                                                                                                                               
Enabling module streams:
 php                                                          remi-8.3                                                                    

Transaction Summary
===========================================================================================================================================
Install  8 Packages

Total download size: 5.7 M
Installed size: 28 M
Is this ok [y/N]: y
Downloading Packages:
(1/8): oniguruma5php-6.9.9-2.el9.remi.aarch64.rpm                                                           84 kB/s | 213 kB     00:02    
(2/8): php-common-8.3.15-1.el9.remi.aarch64.rpm                                                             87 kB/s | 702 kB     00:08    
(3/8): php-mbstring-8.3.15-1.el9.remi.aarch64.rpm                                                           93 kB/s | 519 kB     00:05    
(4/8): php-xml-8.3.15-1.el9.remi.aarch64.rpm                                                                67 kB/s | 150 kB     00:02    
(5/8): httpd-filesystem-2.4.62-1.el9.noarch.rpm                                                             27 kB/s |  12 kB     00:00    
(6/8): nginx-filesystem-1.20.1-20.el9.0.1.noarch.rpm                                                       207 kB/s | 8.4 kB     00:00    
(7/8): php-cli-8.3.15-1.el9.remi.aarch64.rpm                                                               118 kB/s | 2.3 MB     00:19    
(8/8): php-fpm-8.3.15-1.el9.remi.aarch64.rpm                                                               107 kB/s | 1.9 MB     00:17    
-------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                      261 kB/s | 5.7 MB     00:22     
Remi’s RPM repository for Enterprise Linux 9 - aarch64                                                     691 kB/s | 3.1 kB     00:00    
Importing GPG key 0x478F8947:
 Userid     : ”Remi’s RPM repository (https://rpms.remirepo.net/) <remi@remirepo.net>”
 Fingerprint: B1AB F71E 14C9 D748 97E1 98A8 B195 27F1 478F 8947
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el9
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                   1/1 
  Running scriptlet: php-common-8.3.15-1.el9.remi.aarch64                                                                              1/8 
  Installing       : php-common-8.3.15-1.el9.remi.aarch64                                                                              1/8 
  Running scriptlet: nginx-filesystem-2:1.20.1-20.el9.0.1.noarch                                                                       2/8 
  Installing       : nginx-filesystem-2:1.20.1-20.el9.0.1.noarch                                                                       2/8 
  Running scriptlet: httpd-filesystem-2.4.62-1.el9.noarch                                                                              3/8 
  Installing       : httpd-filesystem-2.4.62-1.el9.noarch                                                                              3/8 
  Installing       : oniguruma5php-6.9.9-2.el9.remi.aarch64                                                                            4/8 
  Installing       : php-mbstring-8.3.15-1.el9.remi.aarch64                                                                            5/8 
  Installing       : php-fpm-8.3.15-1.el9.remi.aarch64                                                                                 6/8 
  Running scriptlet: php-fpm-8.3.15-1.el9.remi.aarch64                                                                                 6/8 
  Installing       : php-cli-8.3.15-1.el9.remi.aarch64                                                                                 7/8 
  Installing       : php-xml-8.3.15-1.el9.remi.aarch64                                                                                 8/8 
  Running scriptlet: php-xml-8.3.15-1.el9.remi.aarch64                                                                                 8/8 
  Verifying        : oniguruma5php-6.9.9-2.el9.remi.aarch64                                                                            1/8 
  Verifying        : php-cli-8.3.15-1.el9.remi.aarch64                                                                                 2/8 
  Verifying        : php-common-8.3.15-1.el9.remi.aarch64                                                                              3/8 
  Verifying        : php-fpm-8.3.15-1.el9.remi.aarch64                                                                                 4/8 
  Verifying        : php-mbstring-8.3.15-1.el9.remi.aarch64                                                                            5/8 
  Verifying        : php-xml-8.3.15-1.el9.remi.aarch64                                                                                 6/8 
  Verifying        : httpd-filesystem-2.4.62-1.el9.noarch                                                                              7/8 
  Verifying        : nginx-filesystem-2:1.20.1-20.el9.0.1.noarch                                                                       8/8 

Installed:
  httpd-filesystem-2.4.62-1.el9.noarch        nginx-filesystem-2:1.20.1-20.el9.0.1.noarch      oniguruma5php-6.9.9-2.el9.remi.aarch64     
  php-cli-8.3.15-1.el9.remi.aarch64           php-common-8.3.15-1.el9.remi.aarch64             php-fpm-8.3.15-1.el9.remi.aarch64          
  php-mbstring-8.3.15-1.el9.remi.aarch64      php-xml-8.3.15-1.el9.remi.aarch64               

Complete!

間違えて8.3をインストールしてしまったwww
ということで、確認。

$ which php
/usr/bin/php
$ php -v
PHP 8.3.15 (cli) (built: Dec 17 2024 18:18:02) (NTS gcc aarch64)
Copyright (c) The PHP Group
Zend Engine v4.3.15, Copyright (c) Zend Technologies

そのまま8.4を入れたら、8.3と共存できるんかな、と思ったらそうでもないらしく。エラー。

$ sudo dnf module install php:remi-8.4

Last metadata expiration check: 0:07:21 ago on Mon Dec 30 21:32:58 2024.
Dependencies resolved.
The operation would result in switching of module 'php' stream 'remi-8.3' to stream 'remi-8.4'
Error: It is not possible to switch enabled streams of a module unless explicitly enabled via configuration option module_stream_switch.
It is recommended to rather remove all installed content from the module, and reset the module using 'dnf module reset <module_name>' command. After you reset the module, you can install the other stream.
# なんか知らんけど、一旦モジュールをリセットしてからやり直せと言われたので素直に言うこと聞いてみる
[yngdrsk@localhost ~]$ sudo dnf module reset php
Last metadata expiration check: 0:09:05 ago on Mon Dec 30 21:32:58 2024.
Dependencies resolved.
===========================================================================================================================================
 Package                          Architecture                    Version                           Repository                        Size
===========================================================================================================================================
Disabling module profiles:
 php/common                                                                                                                               
Resetting modules:
 php                                                                                                                                      

Transaction Summary
===========================================================================================================================================

Is this ok [y/N]: y
Complete!

それから8.4を入れてみると、ちゃんと出来た。

$ sudo dnf module install php:remi-8.4
Last metadata expiration check: 0:09:50 ago on Mon Dec 30 21:32:58 2024.
Dependencies resolved.
===========================================================================================================================================
 Package                          Architecture                Version                               Repository                        Size
===========================================================================================================================================
Upgrading:
 php-cli                          aarch64                     8.4.2-1.el9.remi                      remi-modular                     2.3 M
 php-common                       aarch64                     8.4.2-1.el9.remi                      remi-modular                     739 k
 php-fpm                          aarch64                     8.4.2-1.el9.remi                      remi-modular                     1.9 M
 php-mbstring                     aarch64                     8.4.2-1.el9.remi                      remi-modular                     526 k
 php-xml                          aarch64                     8.4.2-1.el9.remi                      remi-modular                     904 k
Installing module profiles:
 php/common                                                                                                                               
Enabling module streams:
 php                                                          remi-8.4                                                                    

Transaction Summary
===========================================================================================================================================
Upgrade  5 Packages

Total download size: 6.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): php-common-8.4.2-1.el9.remi.aarch64.rpm                                                              93 kB/s | 739 kB     00:07    
(2/5): php-mbstring-8.4.2-1.el9.remi.aarch64.rpm                                                            81 kB/s | 526 kB     00:06    
(3/5): php-fpm-8.4.2-1.el9.remi.aarch64.rpm                                                                129 kB/s | 1.9 MB     00:15    
(4/5): php-cli-8.4.2-1.el9.remi.aarch64.rpm                                                                101 kB/s | 2.3 MB     00:23    
(5/5): php-xml-8.4.2-1.el9.remi.aarch64.rpm                                                                 95 kB/s | 904 kB     00:09    
-------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                      263 kB/s | 6.4 MB     00:24     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                   1/1 
  Running scriptlet: php-common-8.4.2-1.el9.remi.aarch64                                                                              1/10 
  Upgrading        : php-common-8.4.2-1.el9.remi.aarch64                                                                              1/10 
  Upgrading        : php-cli-8.4.2-1.el9.remi.aarch64                                                                                 2/10 
  Upgrading        : php-fpm-8.4.2-1.el9.remi.aarch64                                                                                 3/10 
  Running scriptlet: php-fpm-8.4.2-1.el9.remi.aarch64                                                                                 3/10 
  Upgrading        : php-mbstring-8.4.2-1.el9.remi.aarch64                                                                            4/10 
  Upgrading        : php-xml-8.4.2-1.el9.remi.aarch64                                                                                 5/10 
  Cleanup          : php-xml-8.3.15-1.el9.remi.aarch64                                                                                6/10 
  Cleanup          : php-mbstring-8.3.15-1.el9.remi.aarch64                                                                           7/10 
  Running scriptlet: php-fpm-8.3.15-1.el9.remi.aarch64                                                                                8/10 
  Cleanup          : php-fpm-8.3.15-1.el9.remi.aarch64                                                                                8/10 
  Cleanup          : php-cli-8.3.15-1.el9.remi.aarch64                                                                                9/10 
  Cleanup          : php-common-8.3.15-1.el9.remi.aarch64                                                                            10/10 
  Running scriptlet: php-common-8.3.15-1.el9.remi.aarch64                                                                            10/10 
  Verifying        : php-cli-8.4.2-1.el9.remi.aarch64                                                                                 1/10 
  Verifying        : php-cli-8.3.15-1.el9.remi.aarch64                                                                                2/10 
  Verifying        : php-common-8.4.2-1.el9.remi.aarch64                                                                              3/10 
  Verifying        : php-common-8.3.15-1.el9.remi.aarch64                                                                             4/10 
  Verifying        : php-fpm-8.4.2-1.el9.remi.aarch64                                                                                 5/10 
  Verifying        : php-fpm-8.3.15-1.el9.remi.aarch64                                                                                6/10 
  Verifying        : php-mbstring-8.4.2-1.el9.remi.aarch64                                                                            7/10 
  Verifying        : php-mbstring-8.3.15-1.el9.remi.aarch64                                                                           8/10 
  Verifying        : php-xml-8.4.2-1.el9.remi.aarch64                                                                                 9/10 
  Verifying        : php-xml-8.3.15-1.el9.remi.aarch64                                                                               10/10 

Upgraded:
  php-cli-8.4.2-1.el9.remi.aarch64                php-common-8.4.2-1.el9.remi.aarch64           php-fpm-8.4.2-1.el9.remi.aarch64          
  php-mbstring-8.4.2-1.el9.remi.aarch64           php-xml-8.4.2-1.el9.remi.aarch64             

Complete!

Upgradedと言っているので、まあそういうことなんじゃろ。

$ php -v
PHP 8.4.2 (cli) (built: Dec 17 2024 15:31:31) (NTS gcc aarch64)
Copyright (c) The PHP Group
Built by Remi’s RPM repository <https://rpms.remirepo.net/> #StandWithUkraine
Zend Engine v4.4.2, Copyright (c) Zend Technologies

OK、完了!!

Apache2.4のインストール

続いてApacheをインストールします。

# バージョン確認
$ dnf list httpd
Last metadata expiration check: 0:23:03 ago on Mon Dec 30 21:27:17 2024.
Available Packages
httpd.aarch64                                                    2.4.62-1.el9                                                     appstream

# これでいいのでそのままインストール

$ sudo dnf -y install httpd

# 完了!

$ httpd -v
Server version: Apache/2.4.62 (Rocky Linux)
Server built:   Aug  3 2024 00:00:00

confファイルの編集はまあいつも通りやっておくということで、ここでは割愛。

$ vim /etc/httpd/conf/httpd.conf

# 自動起動は設定しておく
$ systemctl start httpd
$ systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

これでブラウザから 192.168.64.8 にアクセス。

よし、と。
で、Apacheが使うディレクトリが /var/www/html なので、次回はここにUTMとの共有ディレクトリを設定しようと思う。

2025/01/01開発環境Apache,MariaDB,MySQL,php,remi,RockyLinux,UTM

Posted by YANAGIDAryosuke