環境
- PHP 7.4
どのphp.ini使えばいいんだ問題
DockerのPHPでは/usr/local/etc/php/php.iniがルートのphp.iniになっている
root@e2459ffbe39f:/var/www/html# php -i|grep php.ini Configuration File (php.ini) Path => /usr/local/etc/php
が、肝心の/usr/local/etc/php/php.iniはデフォルトではいない。その代わり、php.ini-developmentとphp.ini-productionが別途同じディレクトリにいる
root@e2459ffbe39f:/usr/local/etc/php# ls -l total 148 drwxr-xr-x 1 root root 4096 Jul 12 09:22 conf.d -rw-r--r-- 1 root root 72554 Jul 12 09:22 php.ini-development -rw-r--r-- 1 root root 72584 Jul 12 09:22 php.ini-production
ってことは自分でイメージ作るときは適宜開発用と本番用でphp.iniをコピってくれってことなのか。
とりあえず違いをdiffコマンドで確認してみる
php.ini-developmentとphp.ini-productionの違い
root@a9133efa6266:/usr/local/etc/php# diff -u php.ini-development php.ini-production ;;;;;;;;;;;;;;;;;;; ; Quick Reference ; @@ -365,7 +365,7 @@ ; In production, it is recommended to turn this setting on to prohibit the output ; of sensitive information in stack traces ; Default: Off -zend.exception_ignore_args = Off +zend.exception_ignore_args = On ;;;;;;;;;;;;;;;;; ; Miscellaneous ; @@ -462,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 @@ -479,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 @@ -490,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 @@ -1190,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. @@ -1563,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 @@ -1883,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
エラーを画面に出さないとか、メトリクス取らないとかの値が違っている。違いの表が以下
dev | production | |
---|---|---|
zend.exception_ignore_args | off | on |
error_reporting | E_ALL | E_ALL & ~E_DEPRECATED & ~E_STRICT |
display_errors | On | Off |
display_startup_errors | On | Off |
mysqlnd.collect_memory_statistics | On | Off |
zend.assertions | 1 | -1 |
opcache.huge_code_pages | 0 | 1 |
当然本番ではphp.ini-productionをphp.iniにコピーして使ったほうがいいのがわかった。
デフォルトとphp.ini-developmentと違い
デフォルトではphp.iniがないが、php.ini-developmentをphp.iniにリネームして使ったときと同じになるのかというと「ならない」検証方法はphp -iの結果をdiffで比較。
実は微妙に差があるので比較表が以下 display_startup_errorsの値とか結構重要なのも変わっている。
なし | dev | |
---|---|---|
display_startup_errors | Off | On |
enable_dl | On | Off |
error_reporting | no Value | 32767 |
log_errors | Off | On |
request_order | no Value | GP |
short_open_tag | On | Off |
variables_order | EGPCS | GPCS |
Collecting memory statistics | No | Yes |
session.cookie_httponly | 0 | No value |
session.gc_divisor | 100 | 1000 |
session.sid_bits_per_character | 4 | 5 |
session.sid_length | 32 | 26 |
これを見る限り、デフォルトのままPHPのイメージを使用するのは微妙で、明示的にphp.ini-developmentをphp.iniにコピーして使ったほうがよさそう
生のdiffが以下
-display_startup_errors => Off => Off +display_startup_errors => On => On -enable_dl => On => On +enable_dl => Off => Off -error_reporting => no value => no value +error_reporting => 32767 => 32767 -log_errors => Off => Off +log_errors => On => On -request_order => no value => no value +request_order => GP => GP -short_open_tag => On => On +short_open_tag => Off => Off -variables_order => EGPCS => EGPCS +variables_order => GPCS => GPCS -Collecting memory statistics => No +Collecting memory statistics => Yes -session.cookie_httponly => 0 => 0 +session.cookie_httponly => no value => no value -session.gc_divisor => 100 => 100 +session.gc_divisor => 1000 => 1000 -session.sid_bits_per_character => 4 => 4 -session.sid_length => 32 => 32 +session.sid_bits_per_character => 5 => 5 +session.sid_length => 26 => 26