【CentOS stream 9】 phpをインストール
CentOS stream 9に 「php」をインストールします。
phpのバージョンは「php8.0」または「php8.1」で、VPSはConoHa VPSを使用しています。
関連記事 Apache系インストール 1.ConoHa VPS のSSHセキュリティを強化する 2.【CentOS stream 9】 Apacheをインストールする 3.【CentOS stream 9】 Maria DBをインストールする 4.【CentOS stream 9】 phpをインストールする 5.【CentOS stream 9】 composerをインストールする
関連記事 Nginx系インストール 1.ConoHa VPS のSSHセキュリティを強化する 2.【CentOS stream 9】 Nginxをインストールする 3.【CentOS stream 9】 Maria DBをインストールする 4.【CentOS stream 9】 phpをインストールする 5.【CentOS stream 9】 Nginxでphp、phpMyAdminを使う 6.【CentOS stream 9】 composerをインストールする 7.【CentOS stream 9】 Nginxに let's encrypt SSL証明書インストール
関連記事 ドメイン ConoHa WING VPS に サブドメインを追加する
Contents
事前確認:リポジトリの確認
dnf repolist allコマンドでリポジトリの確認
# dnf repolist all repo id repo name status appstream CentOS Stream 9 - AppStream enabled appstream-debug CentOS Stream 9 - AppStream - Debug disabled appstream-source CentOS Stream 9 - AppStream - Source disabled baseos CentOS Stream 9 - BaseOS enabled baseos-debug CentOS Stream 9 - BaseOS - Debug disabled baseos-source CentOS Stream 9 - BaseOS - Source disabled crb CentOS Stream 9 - CRB disabled crb-debug CentOS Stream 9 - CRB - Debug disabled crb-source CentOS Stream 9 - CRB - Source disabled epel Extra Packages for Enterprise Linux 9 - x86 enabled epel-debuginfo Extra Packages for Enterprise Linux 9 - x86 disabled epel-next Extra Packages for Enterprise Linux 9 - Nex enabled epel-next-debuginfo Extra Packages for Enterprise Linux 9 - Nex disabled epel-next-source Extra Packages for Enterprise Linux 9 - Nex disabled epel-next-testing Extra Packages for Enterprise Linux 9 - Nex disabled epel-next-testing-debuginfo Extra Packages for Enterprise Linux 9 - Nex disabled epel-next-testing-source Extra Packages for Enterprise Linux 9 - Nex disabled epel-source Extra Packages for Enterprise Linux 9 - x86 disabled epel-testing Extra Packages for Enterprise Linux 9 - Tes disabled epel-testing-debuginfo Extra Packages for Enterprise Linux 9 - Tes disabled epel-testing-source Extra Packages for Enterprise Linux 9 - Tes disabled highavailability CentOS Stream 9 - HighAvailability disabled highavailability-debug CentOS Stream 9 - HighAvailability - Debug disabled highavailability-source CentOS Stream 9 - HighAvailability - Source disabled nfv CentOS Stream 9 - NFV disabled nfv-debug CentOS Stream 9 - NFV - Debug disabled nfv-source CentOS Stream 9 - NFV - Source disabled resilientstorage CentOS Stream 9 - ResilientStorage disabled resilientstorage-debug CentOS Stream 9 - ResilientStorage - Debug disabled resilientstorage-source CentOS Stream 9 - ResilientStorage - Source disabled rt CentOS Stream 9 - RT disabled rt-debug CentOS Stream 9 - RT - Debug disabled rt-source CentOS Stream 9 - RT - Source disabled
dnf infoコマンドでインストールされるphpバージョンの確認
# dnf info php Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Last metadata expiration check: 0:49:17 ago on Wed 01 Jun 2022 11:55:29 PM JST. Available Packages Name : php Version : 8.0.13 Release : 1.el9 Architecture : x86_64 Size : 10 k Source : php-8.0.13-1.el9.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のインストール (php 8.0) appstream
dnf install phpコマンドでphpをインストール
# dnf install php
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Last metadata expiration check: 0:50:19 ago on Wed 01 Jun 2022 11:55:29 PM JST.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
php x86_64 8.0.13-1.el9 appstream 10 k
Installing dependencies:
apr x86_64 1.7.0-11.el9 appstream 123 k
apr-util x86_64 1.6.1-20.el9 appstream 95 k
apr-util-bdb x86_64 1.6.1-20.el9 appstream 14 k
httpd-filesystem noarch 2.4.51-8.el9 appstream 15 k
httpd-tools x86_64 2.4.51-8.el9 appstream 84 k
oniguruma x86_64 6.9.6-1.el9.5 appstream 218 k
php-common x86_64 8.0.13-1.el9 appstream 682 k
Installing weak dependencies:
apr-util-openssl x86_64 1.6.1-20.el9 appstream 16 k
httpd x86_64 2.4.51-8.el9 appstream 1.5 M
mod_http2 x86_64 1.15.19-2.el9 appstream 150 k
mod_lua x86_64 2.4.51-8.el9 appstream 62 k
php-cli x86_64 8.0.13-1.el9 appstream 3.1 M
php-fpm x86_64 8.0.13-1.el9 appstream 1.6 M
php-mbstring x86_64 8.0.13-1.el9 appstream 472 k
php-opcache x86_64 8.0.13-1.el9 appstream 512 k
php-pdo x86_64 8.0.13-1.el9 appstream 88 k
php-xml x86_64 8.0.13-1.el9 appstream 138 k
Transaction Summary
================================================================================
Install 18 Packages
Total download size: 8.8 M
Installed size: 42 M
Is this ok [y/N]:y
yを入力してエンター
Downloading Packages:
(1/18): apr-util-bdb-1.6.1-20.el9.x86_64.rpm 400 kB/s | 14 kB 00:00
(2/18): apr-util-openssl-1.6.1-20.el9.x86_64.rp 1.3 MB/s | 16 kB 00:00
(3/18): apr-util-1.6.1-20.el9.x86_64.rpm 1.7 MB/s | 95 kB 00:00
(4/18): apr-1.7.0-11.el9.x86_64.rpm 1.9 MB/s | 123 kB 00:00
(5/18): httpd-filesystem-2.4.51-8.el9.noarch.rp 1.1 MB/s | 15 kB 00:00
(6/18): httpd-tools-2.4.51-8.el9.x86_64.rpm 3.5 MB/s | 84 kB 00:00
(7/18): mod_http2-1.15.19-2.el9.x86_64.rpm 4.8 MB/s | 150 kB 00:00
(8/18): mod_lua-2.4.51-8.el9.x86_64.rpm 4.6 MB/s | 62 kB 00:00
(9/18): php-8.0.13-1.el9.x86_64.rpm 746 kB/s | 10 kB 00:00
(10/18): oniguruma-6.9.6-1.el9.5.x86_64.rpm 4.6 MB/s | 218 kB 00:00
(11/18): httpd-2.4.51-8.el9.x86_64.rpm 11 MB/s | 1.5 MB 00:00
(12/18): php-common-8.0.13-1.el9.x86_64.rpm 11 MB/s | 682 kB 00:00
(13/18): php-fpm-8.0.13-1.el9.x86_64.rpm 23 MB/s | 1.6 MB 00:00
(14/18): php-mbstring-8.0.13-1.el9.x86_64.rpm 8.3 MB/s | 472 kB 00:00
(15/18): php-pdo-8.0.13-1.el9.x86_64.rpm 5.5 MB/s | 88 kB 00:00
(16/18): php-opcache-8.0.13-1.el9.x86_64.rpm 12 MB/s | 512 kB 00:00
(17/18): php-xml-8.0.13-1.el9.x86_64.rpm 7.8 MB/s | 138 kB 00:00
(18/18): php-cli-8.0.13-1.el9.x86_64.rpm 6.2 MB/s | 3.1 MB 00:00
--------------------------------------------------------------------------------
Total 6.2 MB/s | 8.8 MB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : php-common-8.0.13-1.el9.x86_64 1/18
Installing : apr-1.7.0-11.el9.x86_64 2/18
Installing : apr-util-bdb-1.6.1-20.el9.x86_64 3/18
Installing : apr-util-openssl-1.6.1-20.el9.x86_64 4/18
Installing : apr-util-1.6.1-20.el9.x86_64 5/18
Running scriptlet: httpd-filesystem-2.4.51-8.el9.noarch 6/18
useradd warning: apache's uid 48 outside of the SYS_UID_MIN 201 and SYS_UID_MAX 999 range.
Installing : httpd-filesystem-2.4.51-8.el9.noarch 6/18
Installing : php-fpm-8.0.13-1.el9.x86_64 7/18
Running scriptlet: php-fpm-8.0.13-1.el9.x86_64 7/18
Installing : httpd-tools-2.4.51-8.el9.x86_64 8/18
Installing : mod_http2-1.15.19-2.el9.x86_64 9/18
Installing : mod_lua-2.4.51-8.el9.x86_64 10/18
Installing : httpd-2.4.51-8.el9.x86_64 11/18
Running scriptlet: httpd-2.4.51-8.el9.x86_64 11/18
Installing : php-cli-8.0.13-1.el9.x86_64 12/18
Installing : php-opcache-8.0.13-1.el9.x86_64 13/18
Installing : php-pdo-8.0.13-1.el9.x86_64 14/18
Installing : php-xml-8.0.13-1.el9.x86_64 15/18
Installing : oniguruma-6.9.6-1.el9.5.x86_64 16/18
Installing : php-mbstring-8.0.13-1.el9.x86_64 17/18
Installing : php-8.0.13-1.el9.x86_64 18/18
Running scriptlet: httpd-2.4.51-8.el9.x86_64 18/18
Running scriptlet: php-8.0.13-1.el9.x86_64 18/18
Verifying : apr-1.7.0-11.el9.x86_64 1/18
Verifying : apr-util-1.6.1-20.el9.x86_64 2/18
Verifying : apr-util-bdb-1.6.1-20.el9.x86_64 3/18
Verifying : apr-util-openssl-1.6.1-20.el9.x86_64 4/18
Verifying : httpd-2.4.51-8.el9.x86_64 5/18
Verifying : httpd-filesystem-2.4.51-8.el9.noarch 6/18
Verifying : httpd-tools-2.4.51-8.el9.x86_64 7/18
Verifying : mod_http2-1.15.19-2.el9.x86_64 8/18
Verifying : mod_lua-2.4.51-8.el9.x86_64 9/18
Verifying : oniguruma-6.9.6-1.el9.5.x86_64 10/18
Verifying : php-8.0.13-1.el9.x86_64 11/18
Verifying : php-cli-8.0.13-1.el9.x86_64 12/18
Verifying : php-common-8.0.13-1.el9.x86_64 13/18
Verifying : php-fpm-8.0.13-1.el9.x86_64 14/18
Verifying : php-mbstring-8.0.13-1.el9.x86_64 15/18
Verifying : php-opcache-8.0.13-1.el9.x86_64 16/18
Verifying : php-pdo-8.0.13-1.el9.x86_64 17/18
Verifying : php-xml-8.0.13-1.el9.x86_64 18/18
Installed products updated.
Installed:
apr-1.7.0-11.el9.x86_64 apr-util-1.6.1-20.el9.x86_64
apr-util-bdb-1.6.1-20.el9.x86_64 apr-util-openssl-1.6.1-20.el9.x86_64
httpd-2.4.51-8.el9.x86_64 httpd-filesystem-2.4.51-8.el9.noarch
httpd-tools-2.4.51-8.el9.x86_64 mod_http2-1.15.19-2.el9.x86_64
mod_lua-2.4.51-8.el9.x86_64 oniguruma-6.9.6-1.el9.5.x86_64
php-8.0.13-1.el9.x86_64 php-cli-8.0.13-1.el9.x86_64
php-common-8.0.13-1.el9.x86_64 php-fpm-8.0.13-1.el9.x86_64
php-mbstring-8.0.13-1.el9.x86_64 php-opcache-8.0.13-1.el9.x86_64
php-pdo-8.0.13-1.el9.x86_64 php-xml-8.0.13-1.el9.x86_64
Complete!
最後に「Complete!」と表示されます。
phpのインストール (php 8.1) remiリポジトリ
Remiリポジトリのインストール
# dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Last metadata expiration check: 0:30:24 ago on Tue 07 Jun 2022 01:18:09 AM JST.
remi-release-9.rpm 24 kB/s | 25 kB 00:01
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
remi-release noarch 9.0-6.el9.remi @commandline 25 k
Transaction Summary
================================================================================
Install 1 Package
Total size: 25 k
Installed size: 24 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.0-6.el9.remi.noarch 1/1
Verifying : remi-release-9.0-6.el9.remi.noarch 1/1
Installed products updated.
Installed:
remi-release-9.0-6.el9.remi.noarch
Complete!
通常は使わないように設定
# vi /etc/yum.repos.d/remi-safe.repo
10行目あたり
編集前
enabled=1
編集後
enabled=0
インストール可能なphpバージョンの確認
# dnf module list php
Remi's Modular repository for Enterprise Linux 532 B/s | 833 B 00:01
Remi's Modular repository for Enterprise Linux 1.1 MB/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
Remi's Modular repository for Enterprise Linux 236 kB/s | 545 kB 00:02
Last metadata expiration check: 0:00:01 ago on Tue 07 Jun 2022 01:50:55 AM JST.
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
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
次の手順でphpをインストールできない場合は、正規表現ライブラリ「oniguruma」をインストールしてみる
# dnf --enablerepo=remi install oniguruma5php Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Remi's RPM repository for Enterprise Linux 9 - 461 B/s | 833 B 00:01 Remi's RPM repository for Enterprise Linux 9 - 2.9 MB/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 Remi's RPM repository for Enterprise Linux 9 - 519 kB/s | 1.6 MB 00:03 Last metadata expiration check: 0:00:01 ago on Tue 07 Jun 2022 01:54:07 AM JST. Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Installing: oniguruma5php x86_64 6.9.8-1.el9.remi remi 219 k Transaction Summary ================================================================================ Install 1 Package Total download size: 219 k Installed size: 767 k Is this ok [y/N]: y Downloading Packages: oniguruma5php-6.9.8-1.el9.remi.x86_64.rpm 144 kB/s | 219 kB 00:01 -------------------------------------------------------------------------------- Total 110 kB/s | 219 kB 00:01 Remi's RPM repository for Enterprise Linux 9 - 3.0 MB/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 Installing : oniguruma5php-6.9.8-1.el9.remi.x86_64 1/1 Running scriptlet: oniguruma5php-6.9.8-1.el9.remi.x86_64 1/1 Verifying : oniguruma5php-6.9.8-1.el9.remi.x86_64 1/1 Installed products updated. Installed: oniguruma5php-6.9.8-1.el9.remi.x86_64 Complete!
php8.1のインストール
# dnf module install php:remi-8.1
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Last metadata expiration check: 0:00:44 ago on Tue 07 Jun 2022 02:09:53 AM JST.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing group/module packages:
php-cli x86_64 8.1.6-1.el9.remi remi-modular 5.2 M
php-common x86_64 8.1.6-1.el9.remi remi-modular 827 k
php-fpm x86_64 8.1.6-1.el9.remi remi-modular 1.8 M
php-mbstring x86_64 8.1.6-1.el9.remi remi-modular 517 k
php-xml x86_64 8.1.6-1.el9.remi remi-modular 204 k
Installing dependencies:
httpd-filesystem noarch 2.4.51-8.el9 appstream 15 k
Installing weak dependencies:
nginx-filesystem noarch 1:1.20.1-10.el9 appstream 12 k
Installing module profiles:
php/common
Enabling module streams:
php remi-8.1
Transaction Summary
================================================================================
Install 7 Packages
Total download size: 8.5 M
Installed size: 51 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): httpd-filesystem-2.4.51-8.el9.noarch.rpm 271 kB/s | 15 kB 00:00
(2/7): nginx-filesystem-1.20.1-10.el9.noarch.rp 162 kB/s | 12 kB 00:00
(3/7): php-common-8.1.6-1.el9.remi.x86_64.rpm 475 kB/s | 827 kB 00:01
(4/7): php-mbstring-8.1.6-1.el9.remi.x86_64.rpm 2.2 MB/s | 517 kB 00:00
(5/7): php-fpm-8.1.6-1.el9.remi.x86_64.rpm 846 kB/s | 1.8 MB 00:02
(6/7): php-xml-8.1.6-1.el9.remi.x86_64.rpm 917 kB/s | 204 kB 00:00
(7/7): php-cli-8.1.6-1.el9.remi.x86_64.rpm 1.9 MB/s | 5.2 MB 00:02
--------------------------------------------------------------------------------
Total 2.5 MB/s | 8.5 MB 00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: php-common-8.1.6-1.el9.remi.x86_64 1/7
Installing : php-common-8.1.6-1.el9.remi.x86_64 1/7
Running scriptlet: nginx-filesystem-1:1.20.1-10.el9.noarch 2/7
Installing : nginx-filesystem-1:1.20.1-10.el9.noarch 2/7
Running scriptlet: httpd-filesystem-2.4.51-8.el9.noarch 3/7
useradd warning: apache's uid 48 outside of the SYS_UID_MIN 201 and SYS_UID_MAX 999 range.
Installing : httpd-filesystem-2.4.51-8.el9.noarch 3/7
Installing : php-fpm-8.1.6-1.el9.remi.x86_64 4/7
Running scriptlet: php-fpm-8.1.6-1.el9.remi.x86_64 4/7
Installing : php-cli-8.1.6-1.el9.remi.x86_64 5/7
Installing : php-mbstring-8.1.6-1.el9.remi.x86_64 6/7
Installing : php-xml-8.1.6-1.el9.remi.x86_64 7/7
Running scriptlet: php-xml-8.1.6-1.el9.remi.x86_64 7/7
Verifying : httpd-filesystem-2.4.51-8.el9.noarch 1/7
Verifying : nginx-filesystem-1:1.20.1-10.el9.noarch 2/7
Verifying : php-cli-8.1.6-1.el9.remi.x86_64 3/7
Verifying : php-common-8.1.6-1.el9.remi.x86_64 4/7
Verifying : php-fpm-8.1.6-1.el9.remi.x86_64 5/7
Verifying : php-mbstring-8.1.6-1.el9.remi.x86_64 6/7
Verifying : php-xml-8.1.6-1.el9.remi.x86_64 7/7
Installed products updated.
Installed:
httpd-filesystem-2.4.51-8.el9.noarch nginx-filesystem-1:1.20.1-10.el9.noarch
php-cli-8.1.6-1.el9.remi.x86_64 php-common-8.1.6-1.el9.remi.x86_64
php-fpm-8.1.6-1.el9.remi.x86_64 php-mbstring-8.1.6-1.el9.remi.x86_64
php-xml-8.1.6-1.el9.remi.x86_64
Complete!
phpのバージョン確認
# php -v PHP 8.0.13 (cli) (built: Nov 16 2021 18:07:21) ( NTS gcc x86_64 ) Copyright (c) The PHP Group Zend Engine v4.0.13, Copyright (c) Zend Technologies with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies
# php -v PHP 8.1.6 (cli) (built: May 11 2022 01:14:18) (NTS gcc x86_64) Copyright (c) The PHP Group Zend Engine v4.1.6, Copyright (c) Zend Technologies
# php-fpm -v PHP 8.1.6 (fpm-fcgi) (built: May 11 2022 01:14:18) Copyright (c) The PHP Group Zend Engine v4.1.6, Copyright (c) Zend Technologies
phpの有効化
ApacheをWEBサーバーとして使っている場合
systemctl restart httpd
NginxをWEBサーバーとして使っている場合
関連記事 Nginxでphp、phpMyAdminを使う
phpの動作確認
phpファイルの作成
# touch /var/www/html/info.php
phpファイルを編集
# vi /var/www/html/info.php
「i」を押してインサートモードへ、
<?php phpinfo();?>
このように記述して、「:wq」を入力、エンター押下で保存して終了
ブラウザのアドレスバーに「http://160.251.100.96(VPSのIPアドレス)/info.php」と入力してアクセス
このように表示されればOKですね。
# yum module list reset php -y Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Last metadata expiration check: 0:20:51 ago on Sun 22 May 2022 06:27:40 AM JST. 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 [e] common [d] [i], devel, minimal PHP scripting language Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
次やること 5.【CentOS stream 9】 composerをインストールする または nginxの場合 5.【CentOS stream 9】 Nginxでphp、phpMyAdminを使う
参考サイト
centOS Strem9でApache,PHP,MySQLを設定する
Enterprise Linux 9 Repository – Remi’s RPM repository – Blog
ディスカッション
コメント一覧
まだ、コメントがありません