見出し画像

Mini PC AlumalinuxにPHP 8.2インストール

前回の続きです。PHP8.2をAlumalinuxにインストールします。WebサーバはApache2です。また、デバッガーが使用できるようにxdebugもインストールします。オンライデバッガーは、PhpStormを使用します。
デバック環境を構築するので、実際に運用するサーバは、別に立てたほうがいいかと思います。(デバッガー機能をOFFにすれば、それでもいいですが、構築したDISKをバックアップして、もう1台にする案がいいかと思います)
PHP8.2のインストールには、dnf updateで最新状態にして、PHP8.2をインストールするためのRemiリポジトリを登録します。
その後、8.2を指定してインストールします。
dnf module install php:remi-8.2
基本環境は、これで完了デスガ、データベース(MySQL,MariaDB用)のライブラリやxdebugをインストールするために必要なライブラリもインストールします。
以下に操作履歴を記載します。(一部の情報はカットしています)

PHP 8.2 install

[root@webixserver01 conf]# dnf update
依存関係が解決しました。
行うべきことはありません。
完了しました!

Remiリポジトリを登録します

[root@webixserver01 conf]# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
epel-release-latest-9.noarch.rpm                 14 kB/s |  19 kB     00:01
依存関係が解決しました。
================================================================================
 パッケージ           Arch           バージョン      リポジトリー         サイズ
================================================================================
インストール:
 epel-release         noarch         9-7.el9         @commandline          19 k

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

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

  検証             : epel-release-9-7.el9.noarch                            1/1

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

完了しました!
[root@webixserver01 conf]# dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Extra Packages for Enterprise Linux 9 - x86_64  453 kB/s |  21 MB     00:46
Extra Packages for Enterprise Linux 9 openh264  513  B/s | 2.5 kB     00:04
remi-release-9.rpm                              8.2 kB/s |  30 kB     00:03
依存関係が解決しました。
================================================================================
 パッケージ         Arch         バージョン            リポジトリー       サイズ
================================================================================
インストール:
 remi-release       noarch       9.3-3.el9.remi        @commandline        30 k

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

合計サイズ: 30 k
インストール後のサイズ: 30 k
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                        1/1
  インストール中   : remi-release-9.3-3.el9.remi.noarch                     1/1
  検証             : remi-release-9.3-3.el9.remi.noarch                     1/1

インストール済み:
  remi-release-9.3-3.el9.remi.noarch

完了しました!
[root@webixserver01 conf]# dnf module list php
Remi's Modular repository for Enterprise Linux   40 kB/s | 657 kB     00:16
Safe Remi's RPM repository for Enterprise Linux  46 kB/s | 990 kB     00:21
AlmaLinux 9 - AppStream
Name      Stream       Profiles                       Summary
php       8.1          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

ヒント: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@webixserver01 conf]# dnf module install php:remi-8.2
依存関係が解決しました。
================================================================================
 パッケージ         Arch     バージョン                    リポジトリー   サイズ
================================================================================
group/moduleパッケージをインストール:
 php-cli            x86_64   8.2.17-1.el9.remi             remi-modular   5.4 M
 php-common         x86_64   8.2.17-1.el9.remi             remi-modular   848 k
 php-fpm            x86_64   8.2.17-1.el9.remi             remi-modular   1.8 M
 php-mbstring       x86_64   8.2.17-1.el9.remi             remi-modular   574 k
 php-xml            x86_64   8.2.17-1.el9.remi             remi-modular   213 k
トランザクションの概要
================================================================================
インストール  7 パッケージ

ダウンロードサイズの合計: 9.0 M
インストール後のサイズ: 52 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
--------------------------------------------------------------------------------
合計                                             73 kB/s | 9.0 MB     02:05
Remi's Modular repository for Enterprise Linux  3.0 MB/s | 3.1 kB     00:00
GPG0x478F8947 をインポート中:
 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
これでよろしいですか? [y/N]: y
鍵のインポートに成功しました
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
インストール済み:
  nginx-filesystem-1:1.20.1-14.el9_2.1.alma.1.noarch
  oniguruma5php-6.9.9-1.el9.remi.x86_64
  php-cli-8.2.17-1.el9.remi.x86_64
  php-common-8.2.17-1.el9.remi.x86_64
  php-fpm-8.2.17-1.el9.remi.x86_64
  php-mbstring-8.2.17-1.el9.remi.x86_64
  php-xml-8.2.17-1.el9.remi.x86_64

完了しました!
[root@webixserver01 conf]# php -v
PHP 8.2.17 (cli) (built: Mar 12 2024 14:26:30) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.17, Copyright (c) Zend Technologies


[root@webixserver01 conf]# php-fpm -v
PHP 8.2.17 (fpm-fcgi) (built: Mar 12 2024 14:26:30)
Copyright (c) The PHP Group
Zend Engine v4.2.17, Copyright (c) Zend Technologies


[root@webixserver01 conf]# dnf install php-mysqlnd
依存関係が解決しました。
================================================================================
 パッケージ       Arch        バージョン                リポジトリー      サイズ
================================================================================
インストール:
 php-mysqlnd      x86_64      8.2.17-1.el9.remi         remi-modular      217 k
トランザクションの概要
================================================================================
インストール  2 パッケージ

ダウンロードサイズの合計: 334 k
インストール後のサイズ: 1.4 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
(1/2): php-pdo-8.2.17-1.el9.remi.x86_64.rpm      19 kB/s | 117 kB     00:06
(2/2): php-mysqlnd-8.2.17-1.el9.remi.x86_64.rpm  21 kB/s | 217 kB     00:10
--------------------------------------------------------------------------------
合計                                             31 kB/s | 334 kB     00:10
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                        1/1
インストール済み:
  php-mysqlnd-8.2.17-1.el9.remi.x86_64     php-pdo-8.2.17-1.el9.remi.x86_64

完了しました!
[root@webixserver01 conf]# dnf install php-pear
依存関係が解決しました。
================================================================================
 パッケージ       Arch        バージョン                リポジトリー      サイズ
================================================================================
インストール:
 php-pear         noarch      1:1.10.13-1.el9           appstream         308 k
================================================================================
インストール  2 パッケージ

ダウンロードサイズの合計: 373 k
インストール後のサイズ: 2.4 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
(1/2): php-pear-1.10.13-1.el9.noarch.rpm         81 kB/s | 308 kB     00:03
(2/2): php-process-8.2.17-1.el9.remi.x86_64.rpm  12 kB/s |  64 kB     00:05
--------------------------------------------------------------------------------
合計                                             49 kB/s | 373 kB     00:07
インストール済み:
  php-pear-1:1.10.13-1.el9.noarch      php-process-8.2.17-1.el9.remi.x86_64

完了しました!

[root@webixserver01 conf]# dnf install php-devel
依存関係が解決しました。
================================================================================
 パッケージ              Arch     バージョン               リポジトリー   サイズ
================================================================================
インストール:
トランザクションの概要
================================================================================
インストール  33 パッケージ

ダウンロードサイズの合計: 58 M
インストール後のサイズ: 177 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
--------------------------------------------------------------------------------
合計                                            472 kB/s |  58 MB     02:05
Extra Packages for Enterprise Linux 9 - x86_64  1.6 MB/s | 1.6 kB     00:00
GPG0x3228467C をインポート中:
 Userid     : "Fedora (epel9) <epel@fedoraproject.org>"
 Fingerprint: FF8A D134 4597 106E CE81 3B91 8A38 72BF 3228 467C
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9
これでよろしいですか? [y/N]: y
鍵のインポートに成功しました
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中

インストール済み:
完了しました!
[root@webixserver01 conf]# pecl install xdebug
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading xdebug-3.3.1.tgz ...
Starting to download xdebug-3.3.1.tgz (258,953 bytes)
done: 258,953 bytes
102 source files, building
running: phpize
Configuring for:
PHP Api Version:         20220829
Zend Module Api No:      20220829
Zend Extension Api No:   420220829
building in /var/tmp/pear-build-yokoshi1q0KJ5/xdebug-3.3.1
running: /var/tmp/xdebug/configure --with-php-config=/usr/bin/php-config
running: make
----------------------------------------------------------------------
Libraries have been installed in:
   /var/tmp/pear-build-yokoshi1q0KJ5/xdebug-3.3.1/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/var/tmp/pear-build-yokoshi1q0KJ5/install-xdebug-3.3.1" install
Installing shared extensions:     /var/tmp/pear-build-yokoshi1q0KJ5/install-xdebug-3.3.1/usr/lib64/php/modules/

  +----------------------------------------------------------------------+
  |                                                                      |
  |   INSTALLATION INSTRUCTIONS                                          |
  |   =========================                                          |
  |                                                                      |
  |   See https://xdebug.org/install.php#configure-php for instructions  |
  |   on how to enable Xdebug for PHP.                                   |
  |                                                                      |
  |   Documentation is available online as well:                         |
  |   - A list of all settings:  https://xdebug.org/docs-settings.php    |
  |   - A list of all functions: https://xdebug.org/docs-functions.php   |
  |   - Profiling instructions:  https://xdebug.org/docs-profiling2.php  |
  |   - Remote debugging:        https://xdebug.org/docs-debugger.php    |
  |                                                                      |
  |                                                                      |
  |   NOTE: Please disregard the message                                 |
  |       You should add "extension=xdebug.so" to php.ini                |
  |   that is emitted by the PECL installer. This does not work for      |
  |   Xdebug.                                                            |
  |                                                                      |
  +----------------------------------------------------------------------+


running: find "/var/tmp/pear-build-yokoshi1q0KJ5/install-xdebug-3.3.1" | xargs ls -dils
   735646    0 drwxr-xr-x 3 root root      17  317 21:19 /var/tmp/pear-build-yokoshi1q0KJ5/install-xdebug-3.3.1
   735678    0 drwxr-xr-x 3 root root      19  317 21:19 /var/tmp/pear-build-yokoshi1q0KJ5/install-xdebug-3.3.1/usr
 68499191    0 drwxr-xr-x 3 root root      17  317 21:19 /var/tmp/pear-build-yokoshi1q0KJ5/install-xdebug-3.3.1/usr/lib64
135308162    0 drwxr-xr-x 3 root root      21  317 21:19 /var/tmp/pear-build-yokoshi1q0KJ5/install-xdebug-3.3.1/usr/lib64/php
201487338    0 drwxr-xr-x 2 root root      23  317 21:19 /var/tmp/pear-build-yokoshi1q0KJ5/install-xdebug-3.3.1/usr/lib64/php/modules
201487339 1900 -rwxr-xr-x 1 root root 1943040  317 21:19 /var/tmp/pear-build-yokoshi1q0KJ5/install-xdebug-3.3.1/usr/lib64/php/modules/xdebug.so

Build process completed successfully
Installing '/usr/lib64/php/modules/xdebug.so'
install ok: channel://pecl.php.net/xdebug-3.3.1
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=/usr/lib64/php/modules/xdebug.so" to php.ini
[root@webixserver01 conf]#

簡単にインストールできます。phpとphp-fpmも同時にインストールできます。

[root@webixserver01 conf]# php -v PHP 8.2.17 (cli) (built: Mar 12 2024 14:26:30) (NTS gcc x86_64) Copyright (c) The PHP Group Zend Engine v4.2.17, Copyright (c) Zend Technologies

[root@webixserver01 conf]# php-fpm -v PHP 8.2.17 (fpm-fcgi) (built: Mar 12 2024 14:26:30) Copyright (c) The PHP Group Zend Engine v4.2.17, Copyright (c) Zend Technologies

このあと、php.ini、php-fpm.confやログの設定などをして動作検証です。
業務アプリを開発するには、画像を処理したり、他サーバとの連携やPDF,EXCEL連携などさまざまな機能をつかうことがあります。必要に応じてPHPの拡張ライブラリのインストールも必要です。今回は、基本設定のみ紹介します。
/etc/php.iniの編集(事前に元のファイルをphp.ini.orgでコピーしておきます)

以下、変更例です。環境に応じて、修正してください。

# 以下は例です /etc/php.ini

memory_limit = 8192M                  #RAM容量にあわせて調整してください
error_log = /var/log/php_errors.log   #phpエラーログファイルパスを指定する
post_max_size = 6096M                 #利用目的にあわせて調整してください
upload_max_filesize = 4G              #利用目的にあわせて調整してください
date.timezone = 'Asia/Tokyo'          #コメントアウトを外して、Asia/Tokyoを指定してください
mbstring.language = Japanese
[xdebug]
zend_extension=/usr/lib64/php/modules/xdebug.so
[root@webixserver01 etc]# diff  php.ini php.ini.org
435c435
< memory_limit = 8192M
---
> memory_limit = 128M
595c595
< error_log = /var/log/php_errors.log
---
> ;error_log = php_errors.log
703c703
< post_max_size = 6096M
---
> post_max_size = 8M
855c855
< upload_max_filesize = 4G
---
> upload_max_filesize = 2M
932c932
< date.timezone = 'Asia/Tokyo'
---
> ;date.timezone =
1513c1513
< mbstring.language = Japanese
---
> ;mbstring.language = Japanese
1676,1678d1675
<
< [xdebug]
< zend_extension=/usr/lib64/php/modules/xdebug.so

修正が完了したら、apache2とphp-fpmを再起動します。

# systemctl restart httpd
# systemctl restart php-fpm.service

phpの動作環境を確認します。事前に以下のファイルを作成し、ブラウザからアクセスします。
/var/www/html/phpinfo.php
<?php phpinfo(); ?>

今回は、サーバのアドレスが192.168.13.22として
ブラウザからhttp://192.168.13.22/phpinfo.phpでアクセスしてみます



PHP8.2及びMariaDBアクセス用のmysql、PDO関連のライブラリやXdebugも有効になっていることを確認して完了です。
今回は、ここまでの紹介です。

この記事が気に入ったらサポートをしてみませんか?