VirtualBoxにいれたCentOS8にPHP7.2をインストールしてみた。

今回はこちらのサイトを参考に、VirtualBoxにいれたCentOS8にPHP7.2インストールしてみました。この記事は実施内容の備忘録となります。
www.rem-system.com

1. 環境

2.PHPインストール

まずはdnfコマンドを使用して下記7つのパッケージをインストールしていきます。

php.x86_64
php-xml.x86_64
php-xmlrpc.x86_64
php-mbstring.x86_64
php-gd.x86_64
php-pdo.x86_64
php-mysqlnd.x86_64

dnf install -y php php-mbstring php-xml php-xmlrpc php-gd php-pdo php-mysqlnd

f:id:edasaka:20191213161018p:plain
dnf install -y php php-mbstring php-xml php-xmlrpc php-gd php-pdo php-mysqlnd
f:id:edasaka:20191213161048p:plain
インストール完了

3.PHPのインストール確認

PHPがインストールされたか確認していきます。

dnf list installed | grep php
php-v

f:id:edasaka:20191213161454p:plain
PHPインストール完了

4. php-fpmの設定

php-fpmを設定していきます。

vi /etc/php-fpm.d/www.conf
① ソケット接続用の設定

f:id:edasaka:20191213162636p:plain
修正前
f:id:edasaka:20191213162757p:plain
修正後

②pm.max_childrenの変更
pm.max_children = 25

f:id:edasaka:20191213163129p:plain
修正前
f:id:edasaka:20191213163219p:plain
修正後

③pm.start_serversの変更
pm.start_servers = 10

f:id:edasaka:20191213163321p:plain
修正前
f:id:edasaka:20191213163938p:plain
修正後

④pm.min_spare_servers
pm.min_spare_servers = 10

f:id:edasaka:20191213163732p:plain
修正前
f:id:edasaka:20191213163825p:plain
修正後

⑤pm.max_spare_servers
pm.max_spare_servers = 20

f:id:edasaka:20191213164104p:plain
修正前
f:id:edasaka:20191213164236p:plain
修正後

⑥pm.max_requests
pm.max_requests = 500

f:id:edasaka:20191213164402p:plain
修正前
f:id:edasaka:20191213164456p:plain
修正後

5. php-fpmの起動と自動起動設定

php-fpmを起動し、サーバーを起動した際、自動的にphp-fpmも起動するよう下記コマンドを実施します。

systemctl start php-fpm
systemctl enable php-fpm

f:id:edasaka:20191213165619p:plain
起動と自動起動の設定

6. php.iniの編集

PHPの設定ファイルを編集していきます。

①expose_php
expose_php = Off

f:id:edasaka:20191213205706p:plain
修正前
f:id:edasaka:20191213205829p:plain
修正後

②post_max_size
post_max_size = 20M

f:id:edasaka:20191213205930p:plain
修正前
f:id:edasaka:20191213210022p:plain
修正後

③upload_max_filesize
upload_max_filesize = 20M

f:id:edasaka:20191213210125p:plain
修正前
f:id:edasaka:20191213210208p:plain
修正後

タイムゾーンの設定
date.timezone = "Asia/Tokyo"

f:id:edasaka:20191213210312p:plain
修正前
f:id:edasaka:20191213210419p:plain
修正後

⑤マルチバイト対応(日本語対応)設定
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = UTF-8
mbstring.http_output = pass
mbstring.encoding_translation = On
mbstring.detect_order = auto
mbstring.substitute_character = none

f:id:edasaka:20191213211018p:plain
修正前①
f:id:edasaka:20191213211135p:plain
修正前②
f:id:edasaka:20191213211400p:plain
修正後①
f:id:edasaka:20191213211544p:plain
修正後②

7. php-fpmとhttpdの再起動

php-fpmとhttpdを再起動します。

systemctl restart php-fpm
systemctl restart httpd

f:id:edasaka:20191213211843p:plain
再起動

8. 動作確認

/var/www/htmlに下記index.phpを作成してブラウザで表示すると。。

<?php phpinfo(); ?>

phpinfoが出力できていることを確認できました!

f:id:edasaka:20191214070952p:plain
PHPインストール完了!

以上、VirtualBoxにいれたCentOS8にPHP7.2をインストールしてみた。でした。