在docker-compose中使用apache + php-fpm容器,我无法使php-fpm容器显示任何错误。
docker-compose.yml
version: '3'
services:
php:
build:
context: ./php
ports:
- 9000:9000
volumes:
- ./code:/code
- ./php/www.conf:/usr/local/etc/php-fpm.d/www.conf
environment:
ENVIRONMENT: local
web:
image: httpd:2.4
depends_on:
- php
ports:
- 80:80
volumes:
- ./code:/usr/local/apache2/htdocs
- ./web/httpd.conf:/usr/local/apache2/conf/httpd.conf
depends_on:
- php
php-fpm Dockerfile:
FROM php:5.6-fpm
php-fpm www.conf:
[global]
error_log = /proc/self/fd/2
[www]
user = www-data
group = www-data
listen = nginx:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
; Logging
; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2
clear_env = no
; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes
php_flag[display_errors] = on
php_admin_flag[log_errors] = on
;php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_value[error_reporting] = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED
php_admin_value[display_startup_errors] = on
docker-compose日志仅显示php-fpm访问日志,没有错误日志。
尝试了所有在提议后提出的解决方案,它们可能是重复的:PHP-FPM doesn't write to error log 他们都没有为我工作,请在下面查看我的评论。
答案 0 :(得分:1)
要花很多时间才能使它正常工作。
在文件docker-compose.yml
中,我挂载了日志(因此日志可以保留)
volumes:
- ./phpSettings.conf:/usr/local/etc/php-fpm.d/zzz-phpSettings.conf
- ./logs/php-error.log:/var/log/error.log
- ./logs/php-access.log:/var/log/access.log
在phpSettings.conf
文件中,我有这个:
[www]
user = www-data
group = www-data
listen = 0.0.0.0:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
catch_workers_output = yes
php_admin_flag[log_errors] = on
php_admin_flag[display_errors] = off
php_admin_value[error_reporting] = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED
php_admin_value[error_log] = /var/log/error.log
access.log = /var/log/access.log
php_value[memory_limit] = 512M
php_value[post_max_size] = 24M
php_value[upload_max_filesize] = 24M
在启动docker之前确保已安装的日志文件存在。
窍门似乎是在命名我的设置zzz-phpSettings.conf
,因此最后一个要加载的设置也是如此。我用相同的设置覆盖了默认的docker php image www.conf设置(监听0.0.0.0:9000除外)。
在这种php-fpm + Nginx设置中,我设法将nginx(错误/访问)日志记录到了自己的位置+将php-fpm错误/访问日志也记录到了自己的位置,因此loggins看起来真的很不错。