I am currently using the official
php:7.4-apache image and I wanted to log some info and errors to the docker logs.
I realize that PHP does not log directly, but logs to the Apache2 Server instead since this is the server interpreting PHP.
Still, I tried the direct approach as stated in the official docker docs:
<?php error_log('testlog', 3, '/proc/self/fd/1'); error_log('testerror', 3, '/proc/self/fd/2');
This gave me a "failed to open stream, the file does not exist" warning.
I also noticed that simply calling
error_log('test') creates the following log without being written to stderr:
[Tue Nov 10 11:39:46.005650 2020] [php7:notice] [pid 17] [client 172.25.0.1:56576] test
I tried to figure out if there were any special ways to send a message to Apache2 stdout/stderr, but I was not able to find anything useful.
Is there a way to achieve this or is this simply the wrong way to log PHP within containers?
Source: Docker Questions