LoginSignup
23
25

More than 3 years have passed since last update.

PHP7.4 開発用と本番用の php.ini 設定の違い

Last updated at Posted at 2020-04-20

PHP をインストールすると php.ini-developmentphp.ini-production の2つのファイルが用意されていますが、どのような違いがあるのか分からなかったので diff を取ってみました。

環境

  • PHP 7.4.5

diff する

$ docker run php:7.4.5-cli diff -u /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini-production > diff.txt

diff 結果

--- /usr/local/etc/php/php.ini-development  2020-04-17 11:30:36.000000000 +0000
+++ /usr/local/etc/php/php.ini-production   2020-04-17 11:30:36.000000000 +0000
@@ -83,7 +83,7 @@
 ; development version only in development environments, as errors shown to
 ; application users can inadvertently leak otherwise secure information.

-; This is the php.ini-development INI file.
+; This is the php.ini-production INI file.

 ;;;;;;;;;;;;;;;;;;;
 ; Quick Reference ;
@@ -363,7 +363,9 @@

 ; Allows to include or exclude arguments from stack traces generated for exceptions
 ; Default: Off
-zend.exception_ignore_args = Off
+; In production, it is recommended to turn this setting on to prohibit the output 
+; of sensitive information in stack traces
+zend.exception_ignore_args = On

 ;;;;;;;;;;;;;;;;;
 ; Miscellaneous ;
@@ -460,7 +462,7 @@
 ; Development Value: E_ALL
 ; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
 ; http://php.net/error-reporting
-error_reporting = E_ALL
+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
@@ -477,7 +479,7 @@
 ; Development Value: On
 ; Production Value: Off
 ; http://php.net/display-errors
-display_errors = On
+display_errors = Off

 ; The display of errors which occur during PHP's startup sequence are handled
 ; separately from display_errors. PHP's default behavior is to suppress those
@@ -488,7 +490,7 @@
 ; Development Value: On
 ; Production Value: Off
 ; http://php.net/display-startup-errors
-display_startup_errors = On
+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
@@ -525,7 +527,9 @@
 ; This setting is on by default.
 ;report_zend_debug = 0

-; Store the last error/warning message in $php_errormsg (boolean).
+; Store the last error/warning message in $php_errormsg (boolean). Setting this value
+; to On can assist in debugging and is appropriate for development servers. It should
+; however be disabled on production servers.
 ; This directive is DEPRECATED.
 ; Default Value: Off
 ; Development Value: Off
@@ -1186,7 +1190,7 @@

 ; Enable / Disable collection of memory usage statistics by mysqlnd which can be
 ; used to tune and monitor MySQL operations.
-mysqlnd.collect_memory_statistics = On
+mysqlnd.collect_memory_statistics = Off

 ; Records communication from all extensions using mysqlnd to the specified log
 ; file.
@@ -1559,7 +1563,7 @@
 ; Development Value: 1
 ; Production Value: -1
 ; http://php.net/zend.assertions
-zend.assertions = 1
+zend.assertions = -1

 ; Assert(expr); active by default.
 ; http://php.net/assert.active
@@ -1586,8 +1590,6 @@
 ; http://php.net/assert.quiet-eval
 ;assert.quiet_eval = 0

-
-
 [COM]
 ; path to a file containing GUIDs, IIDs or filenames of files with TypeLibs
 ; http://php.net/com.typelib-file
@@ -1881,7 +1883,7 @@

 ; Enables or disables copying of PHP code (text segment) into HUGE PAGES.
 ; This should improve performance, but requires appropriate OS configuration.
-;opcache.huge_code_pages=0
+;opcache.huge_code_pages=1

 ; Validate cached file permissions.
 ;opcache.validate_permission=0

zend.exception_ignore_args

  • development は Off、production は On
  • 有効にすると例外のスタックトレースに引数情報が出なくなる
  • PHP7.4以降の設定

error_reporting

エラー出力レベルを設定します。

  • development は E_ALL、production は E_ALL & ~E_DEPRECATED & ~E_STRICT
  • E_ALL は 全ての PHP エラーを表示する
  • E_ALL & ~E_DEPRECATED & ~E_STRICT は 非推奨の警告エラーを除く PHP エラーを表示する
    • E_DEPRECATED は コードの相互運用性や互換性を維持するために PHP がコードの変更を提案する
    • E_STRICT は 実行時の注意、将来のバージョンで動作しなくなるコードについて警告する
  • https://www.php.net/manual/ja/errorfunc.constants.php

display_errors

エラーをHTML出力の一部として画面に出力するかどうかを定義します。

  • development は On、production は Off
  • セキュリティ上、本番では Off 推奨

display_startup_errors

display_errorsをonにした場合でも、PHPの起動シーケンスにおいて発生したエラーは表示されません。

  • development は On、production は Off
  • セキュリティ上、本番では Off 推奨

mysqlnd.collect_memory_statistics

さまざまなメモリ統計情報の収集を有効にします。

  • development は On、production は Off
  • phpinfo()mysqli の統計情報を出力するかどうか

zend.assertions

アサーションのコードを生成して実行します

  • development は 1、production は -1
  • 1 アサーションのコードを生成して実行します (開発モード)
  • 0 アサーションのコードは生成しますが実行時にはスキップします (実行しません)
  • -1 アサーションのコードを生成せず、アサーションのコストがゼロになります (実運用モード)

opcache.huge_code_pages

PHPコード(textセグメント)を HUGE PAGE にコピーする機能を有効にしたり、無効にしたりできます。

  • development は 0、production は 1
  • パフォーマンスは向上するはずですが、適切なOSの設定が必要です。

(適切なOSの設定って何...? わからないので 0 にしてます。)

参考

23
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
25