CentOS8.0にPHP7.2をインストールした後に行う基本設定手順をコマンド付きで丁寧に解説します
CentOS8にPHPをインストールできたけれど、そのあとにやる基本設定が分からない、
テストページを表示する方法が分からない、と悩んでいませんか?
前回の記事で、CentOS8.0にPHP7.2をインストールして、php-fpmの設定変更するところまでができました。
次はPHPの基本設定を行い、テスト用のページを作成してブラウザで表示できるところまでを行います。
PHPの基本設定を行い、テスト用のページを作成してブラウザで表示できるところまでを行います
本記事では、下記の内容を解説します。
この記事を書いている私は、某SIerに勤務しながら、WEB系エンジニア・インフラエンジニアに憧れて、
プログラミングおよびインフラ技術の勉強をしています。
私が実機で試したコマンドや画像を載せて書いていますので、記事の信頼性担保に繋がると思います。
前回の記事
souiunogaii.hatenablog.com「/etc/」直下にある「php.ini」ファイルの編集
編集前のファイルのバックアップ
cp -p /etc/php.ini /etc/php.ini.original_bk
[root@SV-NEPTUNE php-fpm.d]# cp -p /etc/php.ini /etc/php.ini.original_bk
「php.ini」ファイルの編集
vi /etc/php.ini
[root@SV-NEPTUNE php-fpm.d]# vi /etc/php.ini
左が編集後、右が編集前
00369 |; Decides whether PHP may expose the fact that it ||00369 |; Decides whether PHP may expose the fact that it 00370 |; (e.g. by adding its signature to the Web server ||00370 |; (e.g. by adding its signature to the Web server 00371 |; threat in any way, but it makes it possible to d||00371 |; threat in any way, but it makes it possible to d 00372 |; on your server or not. ||00372 |; on your server or not. 00373 |; http://php.net/expose-php ||00373 |; http://php.net/expose-php 00374 L|;expose_php = On ||00374 R|expose_php = On 00375 L|expose_php = Off || |
00669 |; Maximum size of POST data that PHP will accept. ||00668 |; Maximum size of POST data that PHP will accept. 00670 |; Its value may be 0 to disable the limit. It is i||00669 |; Its value may be 0 to disable the limit. It is i 00671 |; is disabled through enable_post_data_reading. ||00670 |; is disabled through enable_post_data_reading. 00672 |; http://php.net/post-max-size ||00671 |; http://php.net/post-max-size 00673 L|;post_max_size = 8M ||00672 R|post_max_size = 8M 00674 L|post_max_size = 20M || |
00825 |; Maximum allowed size for uploaded files. ||00823 |; Maximum allowed size for uploaded files. 00826 |; http://php.net/upload-max-filesize ||00824 |; http://php.net/upload-max-filesize 00827 L|;upload_max_filesize = 2M ||00825 R|upload_max_filesize = 2M 00828 L|upload_max_filesize = 20M || |
00902 |[Date] ||00899 |[Date] 00903 |; Defines the default timezone used by the date fu||00900 |; Defines the default timezone used by the date fu 00904 |; http://php.net/date.timezone ||00901 |; http://php.net/date.timezone 00905 |;date.timezone = ||00902 |;date.timezone = 00906 L|date.timezone = "Asia/Tokyo" || |
01509 |[mbstring] ||01505 |[mbstring] 01510 |; language for internal character representation. ||01506 |; language for internal character representation. 01511 |; This affects mb_send_mail() and mbstring.detect_||01507 |; This affects mb_send_mail() and mbstring.detect_ 01512 |; http://php.net/mbstring.language ||01508 |; http://php.net/mbstring.language 01513 |;mbstring.language = Japanese ||01509 |;mbstring.language = Japanese 01514 L|mbstring.language = Japanese || |
01516 |; Use of this INI entry is deprecated, use global ||01511 |; Use of this INI entry is deprecated, use global 01517 |; internal/script encoding. ||01512 |; internal/script encoding. 01518 |; Some encoding cannot work as internal encoding. ||01513 |; Some encoding cannot work as internal encoding. 01519 |; If empty, default_charset or internal_encoding o||01514 |; If empty, default_charset or internal_encoding o 01520 |; The precedence is: default_charset < internal_en||01515 |; The precedence is: default_charset < internal_en 01521 |;mbstring.internal_encoding = ||01516 |;mbstring.internal_encoding = 01522 L|mbstring.internal_encoding = UTF-8 || |
01524 |; Use of this INI entry is deprecated, use global ||01518 |; Use of this INI entry is deprecated, use global 01525 |; http input encoding. ||01519 |; http input encoding. 01526 |; mbstring.encoding_traslation = On is needed to u||01520 |; mbstring.encoding_traslation = On is needed to u 01527 |; If empty, default_charset or input_encoding or m||01521 |; If empty, default_charset or input_encoding or m 01528 |; The precedence is: default_charset < intput_enco||01522 |; The precedence is: default_charset < intput_enco 01529 |; http://php.net/mbstring.http-input ||01523 |; http://php.net/mbstring.http-input 01530 |;mbstring.http_input = ||01524 |;mbstring.http_input = 01531 L|mbstring.http_input = UTF-8 || |
01533 |; Use of this INI entry is deprecated, use global ||01526 |; Use of this INI entry is deprecated, use global 01534 |; http output encoding. ||01527 |; http output encoding. 01535 |; mb_output_handler must be registered as output b||01528 |; mb_output_handler must be registered as output b 01536 |; If empty, default_charset or output_encoding or ||01529 |; If empty, default_charset or output_encoding or 01537 |; The precedence is: default_charset < output_enco||01530 |; The precedence is: default_charset < output_enco 01538 |; To use an output encoding conversion, mbstring's||01531 |; To use an output encoding conversion, mbstring's 01539 |; otherwise output encoding conversion cannot be p||01532 |; otherwise output encoding conversion cannot be p 01540 |; http://php.net/mbstring.http-output ||01533 |; http://php.net/mbstring.http-output 01541 |;mbstring.http_output = ||01534 |;mbstring.http_output = 01542 L|mbstring.http_output = pass || |
01544 |; enable automatic encoding translation according ||01536 |; enable automatic encoding translation according 01545 |; mbstring.internal_encoding setting. Input chars ||01537 |; mbstring.internal_encoding setting. Input chars 01546 |; converted to internal encoding by setting this t||01538 |; converted to internal encoding by setting this t 01547 |; Note: Do _not_ use automatic encoding translatio||01539 |; Note: Do _not_ use automatic encoding translatio 01548 |; portable libs/applications. ||01540 |; portable libs/applications. 01549 |; http://php.net/mbstring.encoding-translation ||01541 |; http://php.net/mbstring.encoding-translation 01550 |;mbstring.encoding_translation = Off ||01542 |;mbstring.encoding_translation = Off 01551 L|mbstring.encoding_translation = On || |
01553 |; automatic encoding detection order. ||01544 |; automatic encoding detection order. 01554 |; "auto" detect order is changed according to mbst||01545 |; "auto" detect order is changed according to mbst 01555 |; http://php.net/mbstring.detect-order ||01546 |; http://php.net/mbstring.detect-order 01556 |;mbstring.detect_order = auto ||01547 |;mbstring.detect_order = auto 01557 L|mbstring.detect_order = auto || |
01559 |; substitute_character used when character cannot ||01549 |; substitute_character used when character cannot 01560 |; one from another ||01550 |; one from another 01561 |; http://php.net/mbstring.substitute-character ||01551 |; http://php.net/mbstring.substitute-character 01562 |;mbstring.substitute_character = none ||01552 |;mbstring.substitute_character = none 01563 L|mbstring.substitute_character = none || |
設定を反映させるためにphp-fpm再起動しステータス確認
systemctl restart php-fpm
[root@SV-NEPTUNE ~]# systemctl restart php-fpm
systemctl status php-fpm
[root@SV-NEPTUNE ~]# systemctl status php-fpm ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor pre> Active: active (running) since Sun 2020-01-05 02:50:15 JST; 9s ago Main PID: 20798 (php-fpm) Status: "Ready to handle connections" Tasks: 11 (limit: 11141) Memory: 35.0M CGroup: /system.slice/php-fpm.service tq20798 php-fpm: master process (/etc/php-fpm.conf) tq20799 php-fpm: pool www tq20800 php-fpm: pool www tq20801 php-fpm: pool www tq20802 php-fpm: pool www tq20803 php-fpm: pool www tq20804 php-fpm: pool www tq20805 php-fpm: pool www tq20806 php-fpm: pool www tq20807 php-fpm: pool www mq20808 php-fpm: pool www 1月 05 02:50:15 SV-NEPTUNE systemd[1]: Stopped The PHP FastCGI Process Manager. 1月 05 02:50:15 SV-NEPTUNE systemd[1]: Starting The PHP FastCGI Process Manage> 1月 05 02:50:15 SV-NEPTUNE php-fpm[20798]: [05-Jan-2020 02:50:15] WARNING: [po>
httpdの再起動とステータス確認
systemctl restart httpd
[root@SV-NEPTUNE ~]# systemctl restart httpd
systemctl status httpd
[root@SV-NEPTUNE ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese> Drop-In: /usr/lib/systemd/system/httpd.service.d mqphp-fpm.conf Active: active (running) since Sun 2020-01-05 02:50:43 JST; 7s ago Docs: man:httpd.service(8) Main PID: 20816 (httpd) Status: "Started, listening on: port 80" Tasks: 213 (limit: 11141) Memory: 24.3M CGroup: /system.slice/httpd.service tq20816 /usr/sbin/httpd -DFOREGROUND tq20818 /usr/sbin/httpd -DFOREGROUND tq20819 /usr/sbin/httpd -DFOREGROUND tq20820 /usr/sbin/httpd -DFOREGROUND mq20821 /usr/sbin/httpd -DFOREGROUND 1月 05 02:50:43 SV-NEPTUNE systemd[1]: Stopped The Apache HTTP Server. 1月 05 02:50:43 SV-NEPTUNE systemd[1]: Starting The Apache HTTP Server... 1月 05 02:50:43 SV-NEPTUNE httpd[20816]: Server configured, listening on: port> 1月 05 02:50:43 SV-NEPTUNE systemd[1]: Started The Apache HTTP Server.
設定変更後のPHP動作確認
php -r 'phpinfo();'
[root@SV-NEPTUNE ~]# php -r 'phpinfo();' phpinfo() PHP Version => 7.2.11 System => Linux SV-NEPTUNE 4.18.0-80.11.2.el8_0.x86_64 #1 SMP Tue Sep 24 11:32:19 UTC 2019 x86_64 Build Date => Oct 9 2018 15:09:36 Server API => Command Line Interface Virtual Directory Support => disabled Configuration File (php.ini) Path => /etc Loaded Configuration File => /etc/php.ini Scan this dir for additional .ini files => /etc/php.d Additional .ini files parsed => /etc/php.d/20-bz2.ini, (中略) PHP License This program is free software; you can redistribute it and/or modify it under the terms of the PHP License as published by the PHP Group and included in the distribution in the file: LICENSE This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. If you did not receive a copy of the PHP license, or have any questions about PHP licensing, please contact license@php.net.
ブラウザChromeで表示確認
テスト用の「test.php」ファイル作成
cd /home/www/html/sv-neptune.net vi phtest/.php
[root@SV-NEPTUNE ~]# cd /home/www/html/sv-neptune.net [root@SV-NEPTUNE sv-neptune.net]# ls -l 合計 4 -rw-r--r-- 1 www www 21 1月 5 01:49 index.html [root@SV-NEPTUNE sv-neptune.net]# vi phtest/.php
<?php phpinfo(); ?>
ブラウザから「test.php」を表示
http://sv-neptune.net/test.php
確認ができたら、「test.php」は削除
rm test.php
[root@SV-NEPTUNE sv-neptune.net]# rm test.php rm: 通常ファイル 'test.php' を削除しますか? y
参考にしたサイト
www.rem-system.comインフラエンジニアになるための勉強のやり方
私は、某SIerに勤務しながら、WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。現在の会社で直接担当している業務の中では、決まった技術しか触れないけれど、
「他にも将来役に立ちそうなインフラ技術を勉強したい」「働きながらでもできる効率的なインフラエンジニアの勉強方法を知りたい」と考えている方のために、
①おすすめの書籍と、②おススメのオンライン学習サイト、③おすすめのエンジニアスクールを紹介します。
働きながら勉強するための、おススメの書籍と、オンラインで学習できるサイトの紹介です。
インフラエンジニアの勉強ができるおススメ書籍
朝の通勤時や帰宅時の電車の中や、社外打合せへの**移動中などに勉強するなら、やはり書籍が一番**だと思います。インフラエンジニアの教科書
LINE社に創業時から在籍しているインフラエンジニア・プロマネの「佐野裕」さんの本です。twitter.com
膨大なトラフィックをさばくLINE社にて構築・保守を行っている現役エンジニアが記すITインフラの必須知識と経験の数々!
サーバ、OS、ネットワーク機器、データセンター、購買と商談、障害対応、大規模インフラ、成長するために必要なスキルなど、基礎知識から実践まで言及。
ITインフラの世界が理解できる珠玉の1冊!
インフラエンジニアの教科書 (C&R研究所) 佐野裕 |
1週間でLPICの基礎が学べる本
Linuxの資格「LPIC」の試験対策を初心者向けに書いた入門書です。Linuxの資格として広く知られているLPICですが、あまり知識の無いまま試験対策を始める人も多いのではないでしょうか。しかし、試験対策書は試験範囲についてのみ解説しているものが多く、初心者が理解するのは困難です。本書は、初心者がスムーズに試験対策を行えるよう、事前に基礎固めを行うLinux入門書です。試験情報や模擬問題も掲載しているので、資格取得を視野に入れた効率的な基礎学習が行えます。
1週間でLPICの基礎が学べる本 第3版 徹底攻略シリーズ (インプレス) 中島能和 |
インフラエンジニアの勉強ができるオンライン学習サイト
Udemy (オンライン動画学習サイト)
Udemy(ユーデミー)は、オンラインで動画で学習できるサービスです。ITエンジニア系の講座もたくさん公開されています。
Udemyの特徴
- ユーザー登録すれば、第1回の講座は無料で視聴できる
- 無料のコンテンツもある
- 過去に受講した人の人数や、受講した人の評価も表示されるので選びやすい
インフラエンジニアの勉強ができる専門スクール
リナックスアカデミー(ITエンジニア専門スクール)
スクールというと、昼間働いている人には難しいかもしれませんが、以下に紹介するスクールには、
Linuxサーバとネットワークとを両分野ともに学べるコースが、
夜間・土日での5か月~7か月の期間で用意されています。
リナックスアカデミー(ITエンジニア専門スクール) http://www.linuxacademy.ne.jp
リナックスアカデミーの特徴
- 初心者でも最短4週間でエンジニアになれる「IT教育専門機関」
- 100%ライブ抗議の「少人数クラス担任制」
- 実務スキルを身につける「PBL(Project Based Learning)」が充実
- 圧倒的な合格実績と「合格保証制度」
- 就職実績と「就職・転職サポート」が充実
リナックスアカデミーが選ばれ続ける最大の理由、それはIT技術に特化した日本初のIT教育専門機関だからということです。他を寄せ付けないカリキュラムと講師の質で日本No.1のオープンソース専門スクールだと認知されています。
スクールとしては世界で初めてLPI(Linux技術者認定機関)プラチナスポンサーに加盟し、LPI-Jアカデミック認定校第一号スクール、OSS-DBアカデミック認定校第一号スクール、PostgreSQL CE認定校、国内唯一のPHP技術者育成認定校Zend Authorized Training Center など、数々の認定を受けています。 先日来日したLPIC資格試験の開発責任者であるMatthew Rice氏にも、「世界でNo.1と言われる日本の市場で、リナックスアカデミーはNo.1のスクールだと言われている。それは素晴らしいことだ」という言葉を頂いています。
リナックスアカデミー(ITエンジニア専門スクール)の資料請求(無料)について詳しく見てみる
以上、読んでいただきありがとうございました。