centos8にdnfコマンドを使ってphp7.4をインストールする
dnfコマンド : だんてぃふぁいど yum。yumの後継コマンド。ソフトウェアの依存関係を解決してインストールできる。
だんてぃふぁいどは"ダンディー"の変化形とのこと。ダンディーなyum。
centos8バージョン
$ cat /etc/redhat-release
CentOS Linux release 8.3.2011
使用可能なバージョンを調べる。7.4が使えることが分かります。
$ dnf module list php
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
php7.4をインストールする。バージョンを指定する場合は、"モジュール名:バージョン"と記載する。
$ dnf module install php:7.4 -y
... インストールされる
$ php -v
PHP 7.4.6 (cli) (built: May 12 2020 08:09:15) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
$ dnf module list php
Last metadata expiration check: 0:28:13 ago on Tue 08 Dec 2020 02:30:41 PM UTC.
CentOS Linux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 [e] common [d] [i], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
ここでphp7.3をインストールしようとすると失敗する。
"dnf module reset "を行う必要があるようだ。
$ dnf module install php:7.3 -y
Last metadata expiration check: 0:26:02 ago on Tue 08 Dec 2020 02:30:41 PM UTC.
Dependencies resolved.
The operation would result in switching of module 'php' stream '7.4' to stream '7.3'
Error: It is not possible to switch enabled streams of a module.
It is recommended to 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.
↓リセットする
$ dnf module reset php
Last metadata expiration check: 0:29:27 ago on Tue 08 Dec 2020 02:30:41 PM UTC.
Dependencies resolved.
=============================================================================================================================================
Package Architecture Version Repository Size
=============================================================================================================================================
Disabling module profiles:
php/common
Resetting modules:
php
Transaction Summary
=============================================================================================================================================
Is this ok [y/N]: y
Complete!
$ dnf module list php
Last metadata expiration check: 0:29:42 ago on Tue 08 Dec 2020 02:30:41 PM UTC.
CentOS Linux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
$ php -v
PHP 7.4.6 (cli) (built: May 12 2020 08:09:15) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
// あれ、7.4使える・・・
// resetではなくremoveすると実際にphpバイナリごと削除される。
php7.3をインストールする
$ dnf module install -y php:7.3
...インストール
$ php -v
PHP 7.3.20 (cli) (built: Jul 7 2020 07:53:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies