メインコンテンツへスキップ
見出し画像

MySQLを開くために、ついにPHPのデバッグファイルを丸裸にします!!

    上のリンク先の続きの作業で、ついにシステムファイルに手を出してしまいます!!

    質問

    /etc/php/8.3/apache2/php.iniに書いてある;;;;;;;;;;;;;;;;;;;や、冒頭の; はどういう意味ですか?

    [PHP]
    計1966行中1~26行目
    ;;;;;;;;;;;;;;;;;;;
    ; About php.ini ;
    ;;;;;;;;;;;;;;;;;;;
    ; PHP's initialization file, generally called php.ini, is responsible for
    ; configuring many of the aspects of PHP's behavior.

    ; PHP attempts to find and load this configuration from a number of locations.
    ; The following is a summary of its search order:
    ; 1. SAPI module specific location.
    ; 2. The PHPRC environment variable.
    ; 3. A number of predefined registry keys on Windows
    ; 4. Current working directory (except CLI)
    ; 5. The web server's directory (for SAPI modules), or directory of PHP
    ; (otherwise in Windows)
    ; 6. The directory from the --with-config-file-path compile time option, or the
    ; Windows directory (usually C:\windows)
    ; See the PHP docs for more specific information.
    ; https://php.net/configuration.file

    ; The syntax of the file is extremely simple. Whitespace and lines
    ; beginning with a semicolon are silently ignored (as you probably guessed).
    ; Section headers (e.g. [Foo]) are also silently ignored, even though
    ; they might mean something in the future.

    回答

    `/etc/php/8.3/apache2/php.ini` の中で、行の先頭にある `;` や `;;;;;;;;;;;;;;;;;;;` はコメントアウトするための記号です。

    - `;;;;;;;;;;;;;;;;;;;` はビジュアル的に区切り線を提供するためによく使われます。
    - `;` で始まる行はコメントとして扱われ、その行の内容はPHPによって実行されません。

    このようにして、設定ファイルの中で説明や注釈を付けることができます。コメントアウトすることで、実際の設定に影響を与えずに情報を提供したり、将来の参考のためにメモを残したりすることができます。

    質問

    122〜145行目のこちらは、なんのためにありますか?

    ; output_buffering
    ; Default Value: Off
    ; Development Value: 4096
    ; Production Value: 4096

    ; register_argc_argv
    ; Default Value: On
    ; Development Value: Off
    ; Production Value: Off

    ; request_order
    ; Default Value: None
    ; Development Value: "GP"
    ; Production Value: "GP"

    ; session.gc_divisor
    ; Default Value: 100
    ; Development Value: 1000
    ; Production Value: 1000

    ; session.sid_bits_per_character
    ; Default Value: 4
    ; Development Value: 5
    ; Production Value: 5

    回答

    これらのセクションは、PHP設定ファイル(php.ini)の特定の設定オプションに対するデフォルト値や推奨値を示しています。各設定オプションについて、以下の3つの値が提供されています。

    1. **Default Value:** デフォルトでは有効になっている設定値。
    2. **Development Value:** 開発環境に推奨される設定値。
    3. **Production Value:** 本番環境に推奨される設定値。

    この情報は、システム管理者がphp.iniの設定を調整する際に役立ちます。設定を変更することで、環境に応じて動作を最適化することが可能です。これらの設定値は、実際のphp.iniファイルで有効化または変更する際の参考資料として提供されています。

    具体的な例を見てみましょう:

    - **output_buffering**
    - Default Value: Off
    - Development Value: 4096
    - Production Value: 4096

    - **register_argc_argv**
    - Default Value: On
    - Development Value: Off
    - Production Value: Off

    このように、各設定オプションの下にある値の説明があることで、どの環境でどの値が適切かを判断しやすくしています。コメントアウトされているので、実行時には影響を与えませんが、設定を見直す際のガイドラインとして非常に役立ちます。

    質問

    conf
    display_errors = Off
    log_errors = On
    error_log = /var/log/php_errors.log

    localhostのデバッグ内容を表示するために上の内容を入れるには、どこに入れればいいのか、という疑問がわきました。また、デバッグが終わったらこちらのコードは外しますか?それとも残したままですか?

    回答

    以下の手順で `php.ini` に設定を追加して、ローカルホストでのデバッグ情報を表示するように設定できます。また、デバッグ後に設定をどうするかについても説明します。

    ### 設定の追加
    1. `/etc/php/8.3/apache2/php.ini` ファイルを編集します。以下のコマンドを使ってテキストエディタを開きます(例:`nano`を使用します)。

    bash
       sudo nano /etc/php/8.3/apache2/php.ini
       



    2. ファイル内で以下の設定を見つけ、それに対応する値を設定します。既存の設定があればコメントアウトして新しい値に置き換えます。もし設定が存在しない場合は、新しく追加します。

    ini
       display_errors = On
       log_errors = On
       error_log = /var/log/php_errors.log
       



    3. 変更を保存してエディタを終了します。

    4. Apacheを再起動して設定を適用します。

    bash
       sudo systemctl restart apache2
       



    ### デバッグ後の設定
    デバッグが終わったら、セキュリティ上の理由から `display_errors` を `Off` に戻すことを強くお勧めします。エラーメッセージには機密情報が含まれることがあり、本番環境ではこれを表示しない方が安全です。

    設定ファイルを再度編集して、以下のように変更します。

    ini
    display_errors = Off



    `log_errors` や `error_log` の設定はそのままにしておくことが一般的です。サーバのエラーログにエラーメッセージを記録することで、後で問題を診断しやすくなるためです。

    以下の手順で設定を戻すことができます。

    1. 再び `php.ini` ファイルを編集します。

    bash
       sudo nano /etc/php/8.3/apache2/php.ini
       



    2. `display_errors` の設定を `Off` に戻します。

    ini
       display_errors = Off
       



    3. 変更を保存してエディタを終了します。

    4. Apacheを再起動します。

    bash
       sudo systemctl restart apache2
       



    これでデバッグ用の設定が終了し、安全な状態に戻ります。

    質問

    下は何をする部分ですか?
    ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
    97~100行目
    ; display_errors
    ; Default Value: On
    ; Development Value: On
    ; Production Value: Off

    107~110行目
    ; error_reporting
    ; Default Value: E_ALL
    ; Development Value: E_ALL
    ; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT

    112~115行目
    ; log_errors
    ; Default Value: Off
    ; Development Value: On
    ; Production Value: On

    88~175行目
    ;;;;;;;;;;;;;;;;;;;
    ; Quick Reference ;
    ;;;;;;;;;;;;;;;;;;;

    ; The following are all the settings which are different in either the production
    ; or development versions of the INIs with respect to PHP's default behavior.
    ; Please see the actual settings later in the document for more details as to why
    ; we recommend these changes in PHP's behavior.

    ; display_errors
    ; Default Value: On
    ; Development Value: On
    ; Production Value: Off

    ; display_startup_errors
    ; Default Value: On
    ; Development Value: On
    ; Production Value: Off

    ; error_reporting
    ; Default Value: E_ALL
    ; Development Value: E_ALL
    ; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT

    ; log_errors
    ; Default Value: Off
    ; Development Value: On
    ; Production Value: On

    ; max_input_time
    ; Default Value: -1 (Unlimited)
    ; Development Value: 60 (60 seconds)
    ; Production Value: 60 (60 seconds)

    ; output_buffering
    ; Default Value: Off
    ; Development Value: 4096
    ; Production Value: 4096

    ; register_argc_argv
    ; Default Value: On
    ; Development Value: Off
    ; Production Value: Off

    ; request_order
    ; Default Value: None
    ; Development Value: "GP"
    ; Production Value: "GP"

    ; session.gc_divisor
    ; Default Value: 100
    ; Development Value: 1000
    ; Production Value: 1000

    ; session.sid_bits_per_character
    ; Default Value: 4
    ; Development Value: 5
    ; Production Value: 5

    ; session.sid_length
    ; Default Value: 32
    ; Development Value: 26
    ; Production Value: 26

    ; short_open_tag
    ; Default Value: On
    ; Development Value: Off
    ; Production Value: Off

    ; variables_order
    ; Default Value: "EGPCS"
    ; Development Value: "GPCS"
    ; Production Value: "GPCS"

    ; zend.assertions
    ; Default Value: 1
    ; Development Value: 1
    ; Production Value: -1

    ; zend.exception_ignore_args
    ; Default Value: Off
    ; Development Value: Off
    ; Production Value: On

    ; zend.exception_string_param_max_len
    ; Default Value: 15
    ; Development Value: 15
    ; Production Value: 0

    回答

    これらのセクションは、設定ファイル `php.ini` の異なる設定値の概要を提供するためのものです。それぞれの設定について、以下の3つの値が示されています:

    1. **Default Value (デフォルト値):** PHPの初期設定時に使われる値。特定の環境(開発または本番)に関係なく、PHPがデフォルトで使用する値です。
    2. **Development Value (開発環境値):** 開発環境で使用することが推奨される設定値。開発中にデバッグ情報を多く表示するために設定されます。
    3. **Production Value (本番環境値):** 本番環境で使用することが推奨される設定値。セキュリティやパフォーマンスを考慮して設定されます。

    例として:

    - **display_errors**
    - Default Value: On
    - Development Value: On
    - Production Value: Off

    これは、デフォルトでは `display_errors` がオンで、開発環境でもオンに設定されますが、本番環境ではオフにすることが推奨されていることを示しています。

    ### セクションの目的
    この部分は、`php.ini` ファイルを編集する際に役立つガイドラインを提供しています。これにより、開発環境と本番環境で適切な設定が行われるようにします。

    ### 特定の設定値の説明

    - **display_errors:** PHPエラーメッセージを表示するかどうかを決定します。通常、開発環境ではオン、本番環境ではオフにします。
    - **error_reporting:** エラーレポートの詳細度を指定します。
    - **log_errors:** エラーメッセージをログファイルに記録するかどうかを決定します。
    - **output_buffering:** 出力バッファリングを有効にするかどうかを決定します。
    - **max_input_time:** PHPスクリプトが入力データを解析するために許可される最大時間を設定します。

    ### 位置と編集
    これらの設定はコメントアウトされていますが、実際に使用するためには `php.ini` ファイルの対応する行を見つけてコメントアウトを外すか、値を設定します。

    例えば、`display_errors` の設定を変更したい場合:

    ini
    display_errors = On   ; 開発環境の場合
    display_errors = Off  ; 本番環境の場合



    `error_reporting` についても同様です:

    ini
    error_reporting = E_ALL                       ; 開発環境の場合
    error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT  ; 本番環境の場合



    ### 注意点
    デバッグが終了したら、特に本番環境ではセキュリティのために `display_errors` をオフにすることが推奨されます。また、他の開発向けの設定も見直してください。それ以外のログ設定などは、本番環境で役立つためそのままにしておくことが一般的です。

    質問

    WindowsからUbuntu24に切り替えてからMySQLが使えなくなってます。phpMyAdminをlodalhostで開こうとするとエラー500が出るのですが、その原因を調べるために、以下をやってました。

    sudo systemctl restart apache2

    localhostを開く⇛500

    sudo tail -n 15 /var/log/apache2/error.log
    sudo tail -n 15 /var/log/php_errors.log

    ですが、エラーログが出てきませんでした。

    この場合、conf
    display_errors = Off
    log_errors = On
    error_log = /var/log/php_errors.logを入力してそのまま変更しない、ということでしょうか?

    回答

    500エラー(Internal Server Error)は、ApacheやPHPの設定に何らかの問題があることを示しています。エラーログが出てこない場合、いくつかの追加ステップを試してエラーの原因を探る必要があります。

    ### ステップ1: PHPエラーログの設定確認と適用

    まず、`php.ini` ファイルに以下の設定を追加または確認して、エラーログが正しく設定されているか確認します。

    1. `/etc/php/8.3/apache2/php.ini` ファイルを編集します。

    bash
       sudo nano /etc/php/8.3/apache2/php.ini
       



    2. 以下の設定を確認または追加し、保存します。

    ini
       display_errors = On
       log_errors = On
       error_log = /var/log/php_errors.log
       



    3. Apacheを再起動して設定を適用します。

    bash
       sudo systemctl restart apache2
       



    ### ステップ2: Apacheのエラーログを確認

    Apacheのエラーログに問題が記録されていないか確認します。

    bash
    sudo tail -n 50 /var/log/apache2/error.log



    これにより、最近の50行のログが表示されます。ログにはエラーメッセージや問題の原因となるヒントが含まれている可能性があります。

    ### ステップ3: 権限確認

    ログファイルが正しく書き込まれているか確認します。ログファイルのパーミッションが適切でない場合、ログが記録されないことがあります。

    bash
    sudo chmod 755 /var/log/php_errors.log
    sudo chown www-data:www-data /var/log/php_errors.log



    ### ステップ4: phpMyAdminのエラーログを確認

    phpMyAdminの設定ファイルも確認します。phpMyAdminの設定に問題があることが原因でエラーが発生する場合があります。

    1. `config.inc.php` ファイルを開きます(通常は `/etc/phpmyadmin/` ディレクトリ内にあります)。

    bash
       sudo nano /etc/phpmyadmin/config.inc.php
       



    2. 必要に応じてエラーログ出力を設定します。

    php
    $cfg['ShowPhpInfo'] = true;



    ### ステップ5: サーバのステータス確認

    サーバのステータスを確認して、すべてのサービスが正常に動作しているか確認します。

    bash
    sudo systemctl status apache2
    sudo systemctl status mysql



    ### ステップ6: デバッグ情報の確認

    必要に応じて、デバッグ情報やエラーメッセージを詳細に表示するための設定を行います。

    php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);



    これらの設定を `php.ini` または `phpmyadmin` の設定ファイルに追加して、詳細なエラーメッセージを表示します。

    ### 結論

    このようにして、一連の設定を確認し、問題の原因を特定します。`display_errors = On` の設定はデバッグ時に有用ですので、問題が解決したら必ず `display_errors` をオフ (`Off`) に戻してセキュリティを保つようにしてください。

    質問

    これは何をしているものですか?
    ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
    189~236行目
    ;;;;;;;;;;;;;;;;;;;;
    ; Language Options ;
    ;;;;;;;;;;;;;;;;;;;;

    ; Enable the PHP scripting language engine under Apache.
    ; https://php.net/engine
    engine = On

    ; This directive determines whether or not PHP will recognize code between
    ; <? and ?> tags as PHP source which should be processed as such. It is
    ; generally recommended that <?php and ?> should be used and that this feature
    ; should be disabled, as enabling it may result in issues when generating XML
    ; documents, however this remains supported for backward compatibility reasons.
    ; Note that this directive does not control the <?= shorthand tag, which can be
    ; used regardless of this directive.
    ; Default Value: On
    ; Development Value: Off
    ; Production Value: Off
    ; https://php.net/short-open-tag
    short_open_tag = Off

    ; The number of significant digits displayed in floating point numbers.
    ; https://php.net/precision
    precision = 14

    ; Output buffering is a mechanism for controlling how much output data
    ; (excluding headers and cookies) PHP should keep internally before pushing that
    ; data to the client. If your application's output exceeds this setting, PHP
    ; will send that data in chunks of roughly the size you specify.
    ; Turning on this setting and managing its maximum buffer size can yield some
    ; interesting side-effects depending on your application and web server.
    ; You may be able to send headers and cookies after you've already sent output
    ; through print or echo. You also may see performance benefits if your server is
    ; emitting less packets due to buffered output versus PHP streaming the output
    ; as it gets it. On production servers, 4096 bytes is a good setting for performance
    ; reasons.
    ; Note: Output buffering can also be controlled via Output Buffering Control
    ; functions.
    ; Possible Values:
    ; On = Enabled and buffer is unlimited. (Use with caution)
    ; Off = Disabled
    ; Integer = Enables the buffer and sets its maximum size in bytes.
    ; Note: This directive is hardcoded to Off for the CLI SAPI
    ; Default Value: Off
    ; Development Value: 4096
    ; Production Value: 4096
    ; https://php.net/output-buffering
    output_buffering = 4096

    270~280行目
    ; Transparent output compression using the zlib library
    ; Valid values for this option are 'off', 'on', or a specific buffer size
    ; to be used for compression (default is 4KB)
    ; Note: Resulting chunk size may vary due to nature of compression. PHP
    ; outputs chunks that are few hundreds bytes each as a result of
    ; compression. If you prefer a larger chunk size for better
    ; performance, enable output_buffering in addition.
    ; Note: You need to use zlib.output_handler instead of the standard
    ; output_handler, or otherwise the output will be corrupted.
    ; https://php.net/zlib.output-compression
    zlib.output_compression = Off

    291~306行目
    ; Implicit flush tells PHP to tell the output layer to flush itself
    ; automatically after every output block. This is equivalent to calling the
    ; PHP function flush() after each and every call to print() or echo() and each
    ; and every HTML block. Turning this option on has serious performance
    ; implications and is generally recommended for debugging purposes only.
    ; https://php.net/implicit-flush
    ; Note: This directive is hardcoded to On for the CLI SAPI
    implicit_flush = Off

    ; The unserialize callback function will be called (with the undefined class'
    ; name as parameter), if the unserializer finds an undefined class
    ; which should be instantiated. A warning appears if the specified function is
    ; not defined, or if the function doesn't include/implement the missing class.
    ; So only set this entry, if you really want to implement such a
    ; callback-function.
    unserialize_callback_func =

    315~321行目
    ; When floats & doubles are serialized, store serialize_precision significant
    ; digits after the floating point. The default value ensures that when floats
    ; are decoded with unserialize, the data will remain the same.
    ; The value is also used for json_encode when encoding double values.
    ; If -1 is used, then dtoa mode 0 is used which automatically select the best
    ; precision.
    serialize_precision = -1

    330~338行目
    ; This directive allows you to disable certain functions.
    ; It receives a comma-delimited list of function names.
    ; https://php.net/disable-functions
    disable_functions =

    ; This directive allows you to disable certain classes.
    ; It receives a comma-delimited list of class names.
    ; https://php.net/disable-classes
    disable_classes =

    369~371行目
    ; Enables or disables the circular reference collector.
    ; https://php.net/zend.enable-gc
    zend.enable_gc = On

    383~399行目
    ; Allows to include or exclude arguments from stack traces generated for exceptions.
    ; In production, it is recommended to turn this setting on to prohibit the output
    ; of sensitive information in stack traces
    ; Default Value: Off
    ; Development Value: Off
    ; Production Value: On
    zend.exception_ignore_args = On

    ; Allows setting the maximum string length in an argument of a stringified stack trace
    ; to a value between 0 and 1000000.
    ; This has no effect when zend.exception_ignore_args is enabled.
    ; Default Value: 15
    ; Development Value: 15
    ; Production Value: 0
    ; In production, it is recommended to set this to 0 to reduce the output
    ; of sensitive information in stack traces.
    zend.exception_string_param_max_len = 0

    回答

    これらのセクションは、`php.ini` ファイルの中でPHPの動作を制御するための設定オプションを定義する部分です。各設定オプションには説明と共に推奨される値がコメントとして書かれており、デフォルト値、開発環境用の値、本番環境用の値が記載されています。

    以下は、各セクションとその主要な設定項目の説明です:

    ### Language Options セクション
    このセクションでは、PHP言語の基本的な動作を制御するオプションが含まれています。

    1. **engine**
    - 説明: PHPエンジンを有効にします。
    - 設定例: `engine = On`

    2. **short_open_tag**
    - 説明: `<? ?>` タグをPHPコードとして認識するかどうかを決定します。推奨されないため、オフにするのが一般的です。
    - 設定例: `short_open_tag = Off`

    3. **precision**
    - 説明: 浮動小数点数の表示に使用する有効桁数を決定します。
    - 設定例: `precision = 14`

    ### Output Buffering セクション
    このセクションは、出力バッファリングの設定を行います。

    1. **output_buffering**
    - 説明: 出力バッファリングを有効にし、その最大バッファサイズを指定します。
    - 設定例: `output_buffering = 4096`

    2. **zlib.output_compression**
    - 説明: zlibライブラリを使用した透明な出力圧縮を有効にします。
    - 設定例: `zlib.output_compression = Off`

    ### Implicit Flush セクション
    このセクションは、暗黙のフラッシュ設定を行います。

    1. **implicit_flush**
    - 説明: すべての出力ブロック後に自動的に出力レイヤーをフラッシュするかどうかを決定します。デバッグに主に使用されます。
    - 設定例: `implicit_flush = Off`

    ### Unserialize Callback Function セクション
    このセクションは、未定義のクラスをアンシリアライズする際にコールバック関数を設定します。

    1. **unserialize_callback_func**
    - 説明: アンシリアライズ時に未定義のクラスが見つかった場合に呼び出されるコールバック関数。
    - 設定例: `unserialize_callback_func = `

    ### Serialize Precision セクション
    このセクションは、浮動小数点数をシリアライズする際の精度を設定します。

    1. **serialize_precision**
    - 説明: シリアライズされた浮動小数点数の有効桁数を決定します。
    - 設定例: `serialize_precision = -1`

    ### Functions and Classes Disabling セクション
    このセクションは、特定の関数やクラスを無効にする設定を行います。

    1. **disable_functions**
    - 説明: 無効にする関数をカンマ区切りで指定します。
    - 設定例: `disable_functions = `

    2. **disable_classes**
    - 説明: 無効にするクラスをカンマ区切りで指定します。
    - 設定例: `disable_classes = `

    ### Circular Reference Collector セクション
    このセクションは、円環参照ガベージコレクタの設定を行います。

    1. **zend.enable_gc**
    - 説明: PHPのガベージコレクタを有効にします。
    - 設定例: `zend.enable_gc = On`

    ### Exception Handling セクション
    このセクションは、例外のスタックトレースに関する設定を行います。

    1. **zend.exception_ignore_args**
    - 説明: スタックトレースで引数を含めるか除外するかを決定します。本番環境ではオンにするのが推奨されます。
    - 設定例: `zend.exception_ignore_args = On`

    2. **zend.exception_string_param_max_len**
    - 説明: スタックトレースの引数の最大文字数を設定します。本番環境では0に設定するのが推奨されます。
    - 設定例: `zend.exception_string_param_max_len = 0`

    これらの設定は、アプリケーションの動作やパフォーマンス、セキュリティに大きな影響を与える可能性があるため、環境や要件に応じて適切に設定する必要があります。

    質問

    下は何をしている文ですか?
    ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
    401~429行目
    ;;;;;;;;;;;;;;;;;
    ; Miscellaneous ;
    ;;;;;;;;;;;;;;;;;

    ; Decides whether PHP may expose the fact that it is installed on the server
    ; (e.g. by adding its signature to the Web server header). It is no security
    ; threat in any way, but it makes it possible to determine whether you use PHP
    ; on your server or not.
    ; https://php.net/expose-php
    expose_php = Off

    ;;;;;;;;;;;;;;;;;;;
    ; Resource Limits ;
    ;;;;;;;;;;;;;;;;;;;

    ; Maximum execution time of each script, in seconds
    ; https://php.net/max-execution-time
    ; Note: This directive is hardcoded to 0 for the CLI SAPI
    max_execution_time = 30

    ; Maximum amount of time each script may spend parsing request data. It's a good
    ; idea to limit this time on productions servers in order to eliminate unexpectedly
    ; long running scripts.
    ; Note: This directive is hardcoded to -1 for the CLI SAPI
    ; Default Value: -1 (Unlimited)
    ; Development Value: 60 (60 seconds)
    ; Production Value: 60 (60 seconds)
    ; https://php.net/max-input-time
    max_input_time = 60

    443~464行目
    ; Maximum amount of memory a script may consume
    ; https://php.net/memory-limit
    memory_limit = 128M

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Error handling and logging ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ; This directive informs PHP of which errors, warnings and notices you would like
    ; it to take action for. The recommended way of setting values for this
    ; directive is through the use of the error level constants and bitwise
    ; operators. The error level constants are below here for convenience as well as
    ; some common settings and their meanings.
    ; By default, PHP is set to take action on all errors, notices and warnings EXCEPT
    ; those related to E_NOTICE and E_STRICT, which together cover best practices and
    ; recommended coding standards in PHP. For performance reasons, this is the
    ; recommend error reporting setting. Your production server shouldn't be wasting
    ; resources complaining about best practices and coding standards. That's what
    ; development servers and development settings are for.
    ; Note: The php.ini-development file has this setting as E_ALL. This
    ; means it pretty much reports everything which is exactly what you want during
    ; development and early testing.

    492~554行目
    ; Common Values:
    ; E_ALL (Show all errors, warnings and notices including coding standards.)
    ; E_ALL & ~E_NOTICE (Show all errors, except for notices)
    ; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.)
    ; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
    ; Default Value: E_ALL
    ; Development Value: E_ALL
    ; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
    ; https://php.net/error-reporting
    error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

    ; This directive controls whether or not and where PHP will output errors,
    ; notices and warnings too. Error output is very useful during development, but
    ; it could be very dangerous in production environments. Depending on the code
    ; which is triggering the error, sensitive information could potentially leak
    ; out of your application such as database usernames and passwords or worse.
    ; For production environments, we recommend logging errors rather than
    ; sending them to STDOUT.
    ; Possible Values:
    ; Off = Do not display any errors
    ; stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
    ; On or stdout = Display errors to STDOUT
    ; Default Value: On
    ; Development Value: On
    ; Production Value: Off
    ; https://php.net/display-errors
    display_errors = Off

    ; The display of errors which occur during PHP's startup sequence are handled
    ; separately from display_errors. We strongly recommend you set this to 'off'
    ; for production servers to avoid leaking configuration details.
    ; Default Value: On
    ; Development Value: On
    ; Production Value: Off
    ; https://php.net/display-startup-errors
    display_startup_errors = Off

    ; Besides displaying errors, PHP can also log errors to locations such as a
    ; server-specific log, STDERR, or a location specified by the error_log
    ; directive found below. While errors should not be displayed on productions
    ; servers they should still be monitored and logging is a great way to do that.
    ; Default Value: Off
    ; Development Value: On
    ; Production Value: On
    ; https://php.net/log-errors
    log_errors = On

    ; Do not log repeated messages. Repeated errors must occur in same file on same
    ; line unless ignore_repeated_source is set true.
    ; https://php.net/ignore-repeated-errors
    ignore_repeated_errors = Off

    ; Ignore source of message when ignoring repeated messages. When this setting
    ; is On you will not log errors with repeated messages from different files or
    ; source lines.
    ; https://php.net/ignore-repeated-source
    ignore_repeated_source = Off

    ; If this parameter is set to Off, then memory leaks will not be shown (on
    ; stdout or in the log). This is only effective in a debug compile, and if
    ; error reporting includes E_WARNING in the allowed list
    ; https://php.net/report-memleaks
    report_memleaks = On

    634~636行目
    ;;;;;;;;;;;;;;;;;
    ; Data Handling ;
    ;;;;;;;;;;;;;;;;;

    651~698行目
    ; This directive determines which super global arrays are registered when PHP
    ; starts up. G,P,C,E & S are abbreviations for the following respective super
    ; globals: GET, POST, COOKIE, ENV and SERVER. There is a performance penalty
    ; paid for the registration of these arrays and because ENV is not as commonly
    ; used as the others, ENV is not recommended on productions servers. You
    ; can still get access to the environment variables through getenv() should you
    ; need to.
    ; Default Value: "EGPCS"
    ; Development Value: "GPCS"
    ; Production Value: "GPCS";
    ; https://php.net/variables-order
    variables_order = "GPCS"

    ; This directive determines which super global data (G,P & C) should be
    ; registered into the super global array REQUEST. If so, it also determines
    ; the order in which that data is registered. The values for this directive
    ; are specified in the same manner as the variables_order directive,
    ; EXCEPT one. Leaving this value empty will cause PHP to use the value set
    ; in the variables_order directive. It does not mean it will leave the super
    ; globals array REQUEST empty.
    ; Default Value: None
    ; Development Value: "GP"
    ; Production Value: "GP"
    ; https://php.net/request-order
    request_order = "GP"

    ; This directive determines whether PHP registers $argv & $argc each time it
    ; runs. $argv contains an array of all the arguments passed to PHP when a script
    ; is invoked. $argc contains an integer representing the number of arguments
    ; that were passed when the script was invoked. These arrays are extremely
    ; useful when running scripts from the command line. When this directive is
    ; enabled, registering these variables consumes CPU cycles and memory each time
    ; a script is executed. For performance reasons, this feature should be disabled
    ; on production servers.
    ; Note: This directive is hardcoded to On for the CLI SAPI
    ; Default Value: On
    ; Development Value: Off
    ; Production Value: Off
    ; https://php.net/register-argc-argv
    register_argc_argv = Off

    ; When enabled, the ENV, REQUEST and SERVER variables are created when they're
    ; first used (Just In Time) instead of when the script starts. If these
    ; variables are not used within a script, having this directive on will result
    ; in a performance gain. The PHP directive register_argc_argv must be disabled
    ; for this directive to have any effect.
    ; https://php.net/auto-globals-jit
    auto_globals_jit = On

    709~732行目
    ; Maximum size of POST data that PHP will accept.
    ; Its value may be 0 to disable the limit. It is ignored if POST data reading
    ; is disabled through enable_post_data_reading.
    ; https://php.net/post-max-size
    post_max_size = 8M

    ; Automatically add files before PHP document.
    ; https://php.net/auto-prepend-file
    auto_prepend_file =

    ; Automatically add files after PHP document.
    ; https://php.net/auto-append-file
    auto_append_file =

    ; By default, PHP will output a media type using the Content-Type header. To
    ; disable this, simply set it to be empty.
    ;
    ; PHP's built-in default media type is set to text/html.
    ; https://php.net/default-mimetype
    default_mimetype = "text/html"

    ; PHP's default character set is set to UTF-8.
    ; https://php.net/default-charset
    default_charset = "UTF-8"

    750~752行目
    ;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Paths and Directories ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;

    763~774行目
    ; The root of the PHP pages, used only if nonempty.
    ; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
    ; if you are running php as a CGI under any web server (other than IIS)
    ; see documentation for security issues. The alternate is to use the
    ; cgi.force_redirect configuration below
    ; https://php.net/doc-root
    doc_root =

    ; The directory under which PHP opens the script using /~username used only
    ; if nonempty.
    ; https://php.net/user-dir
    user_dir =

    786~790行目
    ; Whether or not to enable the dl() function. The dl() function does NOT work
    ; properly in multithreaded servers, such as IIS or Zeus, and is automatically
    ; disabled on them.
    ; https://php.net/enable-dl
    enable_dl = Off

    回答

    これらのPHP設定ファイル (`php.ini`) のセクションは、さまざまなカテゴリーに分かれており、それぞれがPHPの異なる機能や動作を制御するために使用されます。各設定項目には推奨値と共に詳細な説明が付いており、特定の用途や環境に合わせて調整することが可能です。

    以下では、各セクションの内容とその主要な設定項目について説明します。

    ### Miscellaneous セクション

    1. **expose_php**
    - 説明: PHPがインストールされていることをWebサーバのヘッダーで公開するかどうかを決定します。セキュリティ上、オフにすることが一般的です。
    - 設定例: `expose_php = Off`

    ### Resource Limits セクション

    1. **max_execution_time**
    - 説明: 各スクリプトの最大実行時間を秒単位で設定します。これにより、無限ループや長時間実行されるスクリプトを防止します。
    - 設定例: `max_execution_time = 30`

    2. **max_input_time**
    - 説明: 各スクリプトがリクエストデータを解析するために費やせる最大時間を設定します。生産環境では制限することが推奨されます。
    - 設定例: `max_input_time = 60`

    3. **memory_limit**
    - 説明: スクリプトが消費できる最大メモリ量を設定します。この設定により、メモリリークや大量のリソースを消費するスクリプトを防ぐことができます。
    - 設定例: `memory_limit = 128M`

    ### Error Handling and Logging セクション

    1. **error_reporting**
    - 説明: PHPがどのエラー、警告、通知に対してアクションを取るかを決定します。開発環境と本番環境で異なるセットアップをすることが推奨されます。
    - 設定例: `error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT`

    2. **display_errors**
    - 説明: エラー、警告、通知を標準出力に表示するかどうかを決定します。本番環境ではオフにすることが推奨されます。
    - 設定例: `display_errors = Off`

    3. **display_startup_errors**
    - 説明: PHPの起動シーケンス中に発生するエラーを表示するかどうかを決定します。本番環境ではオフにすることが推奨されます。
    - 設定例: `display_startup_errors = Off`

    4. **log_errors**
    - 説明: エラーをログに記録するかどうかを決定します。エラーを表示する代わりに、ログに記録することが推奨されます。
    - 設定例: `log_errors = On`

    5. **ignore_repeated_errors**
    - 説明: 同じエラーメッセージを繰り返しログに記録するかどうかを決定します。
    - 設定例: `ignore_repeated_errors = Off`

    6. **ignore_repeated_source**
    - 説明: 異なるソースやラインからの繰り返されるエラーメッセージを無視するかどうかを決定します。
    - 設定例: `ignore_repeated_source = Off`

    7. **report_memleaks**
    - 説明: メモリリークをレポートするかどうかを決定します。デバッグコンパイル時に有効です。
    - 設定例: `report_memleaks = On`

    ### Data Handling セクション

    1. **variables_order**
    - 説明: スーパグローバル配列が起動時にどの順序で登録されるかを決定します。
    - 設定例: `variables_order = "GPCS"`

    2. **request_order**
    - 説明: REQUESTスーパグローバル配列に登録されるデータの順序を決定します。
    - 設定例: `request_order = "GP"`

    3. **register_argc_argv**
    - 説明: スクリプト実行時の引数($argv と $argc)を登録するかどうかを決定します。本番環境ではオフにすることが推奨されます。
    - 設定例: `register_argc_argv = Off`

    4. **auto_globals_jit**
    - 説明: スーパグローバル変数を最初に使用された時点で作成するかどうかを決定します。この設定によりパフォーマンスが向上する場合があります。
    - 設定例: `auto_globals_jit = On`

    ### Paths and Directories セクション

    1. **doc_root**
    - 説明: PHPページのルートディレクトリを設定します。特にCGIとしてPHPを実行する場合に設定します。
    - 設定例: `doc_root =`

    2. **user_dir**
    - 説明: `/~username` を使用してスクリプトを開く際のディレクトリを設定します。
    - 設定例: `user_dir =`

    3. **enable_dl**
    - 説明: `dl()` 関数を有効にするかどうかを決定します。マルチスレッドサーバ上では自動的に無効になります。
    - 設定例: `enable_dl = Off`

    ### その他の設定項目

    1. **post_max_size**
    - 説明: PHPが受け入れるPOSTデータの最大サイズを設定します。
    - 設定例: `post_max_size = 8M`

    2. **default_mimetype**
    - 説明: PHPのデフォルトのメディアタイプを設定します。
    - 設定例: `default_mimetype = "text/html"`

    3. **default_charset**
    - 説明: PHPのデフォルトの文字セットを設定します。
    - 設定例: `default_charset = "UTF-8"`

    これらの設定は、PHPがどのように動作するかや、どのような場合にエラーを表示またはログに記録するかを細かく制御するために使用されます。環境やアプリケーションの要件に応じて適適適切に設定することが重要です。

    あなたへのおすすめ