バージョン指定してPHP導入

デフォルトはPHP7.2と古いのと、PHP7.4もすでにアクティブサポートは終了し、セキュリティサポートも2022/11をもって終了予定だそうです。

なので、一気にPHP8.1を入れて見たいと思います!
大丈夫か?!

1.オペレーティングシステムの更新

[root@miracle ~]# dnf upgrade --refresh -y

結構時間掛かります。

2.使用可能なPHPバージョンを確認

[root@miracle ~]# dnf module list php
8-latest-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
php 8.0              common [d], devel, minimal       PHP scripting language
Remi's Modular repository for Enterprise Linux 8 - x86_64
Name Stream Profiles Summary
php remi-7.2        common [d], devel, minimal        PHP scripting language
php remi-7.3        common [d], devel, minimal        PHP scripting language
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
ヒント: [d]efault, [e]nabled, [x]disabled, [i]nstalled

PHP7.2がデフォルトになっています。
PHP8.1をインストールの前にモジュールのリセットをします。

[root@miracle ~]# dnf module reset php
依存関係が解決しました。
行うべきことはありません。
完了しました!

PHP8.1を有効にします。

[root@miracle ~]# dnf module enable php:remi-8.1 -y
8-latest-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
php 8.0              common [d], devel, minimal       PHP scripting language
Remi's Modular repository for Enterprise Linux 8 - x86_64
Name Stream Profiles Summary
php remi-7.2        common [d], devel, minimal       PHP scripting language
php remi-7.3        common [d], devel, minimal       PHP scripting language
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], devel, minimal       PHP scripting language
php remi-8.2        common [d], devel, minimal       PHP scripting language
ヒント: [d]efault, [e]nabled, [x]disabled, [i]nstalled

PHP8.1をインストールします。

[root@miracle ~]# dnf install php -y
インストール済み:
nginx-filesystem-1:1.14.1-9.0.1.module+el8+67+e30417db.noarch
php-8.1.10-1.el8.remi.x86_64
php-cli-8.1.10-1.el8.remi.x86_64
php-common-8.1.10-1.el8.remi.x86_64
php-fpm-8.1.10-1.el8.remi.x86_64
php-opcache-8.1.10-1.el8.remi.x86_64
php-pdo-8.1.10-1.el8.remi.x86_64
php-xml-8.1.10-1.el8.remi.x86_64
完了しました!

PHPのバージョン確認

[root@miracle ~]# php -v
PHP 8.1.10 (cli) (built: Aug 30 2022 16:09:36) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
with Zend OPcache v8.1.10, Copyright (c), by Zend Technologies

php.iniの設定

[root@miracle ~]# vi /etc/php.ini
[PHP]ブロック
expose_php = Off ← レスポンスヘッダにPHPのバージョンを表示させない
error_reporting = E_ALL ← 全てのログを出力させる
display_errors = Off ← ブラウザでのエラー表示させない
log_errors = On ← エラーをログに残す
log_errors_max_len = 4096 ← 追加。エラーログの長さを設定、念のため大きめに
error_log = "/var/log/php_errors.log" ← 追加。エラーログ出力先
default_charset = "UTF-8" ← 文字エンコーディング
[Date]ブロック
date.timezone = "Asia/Tokyo" ← タイムゾーン
[mbstring]ブロック
mbstring.language = Japanese ← デフォルト言語
mbstring.internal_encoding = UTF-8 ← 内部文字エンコーディング
mbstring.http_input = auto ← HTTP入力文字エンコーディングのデフォルト
mbstring.detect_order = auto ← 文字エンコーディング検出順序のデフォルト

php-fpmの再起動

[root@miracle ~]# systemctl start php-fpm

Webサーバー再起動

[root@miracle ~]# systemctl restart httpd

PHP確認

[root@miracle ~]# vi /var/www/html/test.php
 <?php 
     phpinfo(); 
?>

http://サーバー名/test.php にアクセスして、下記ページが表示されればOK!

コメント

タイトルとURLをコピーしました