feat(workspaces): stream PHP application logs to the container log stream - #11
Merged
Merged
Conversation
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
PHP's error_log(), warnings and captured worker output were written to the hidden /var/www/log/php-fpm.log file, invisible in docker/Coolify logs. Keep that www-data-owned file as FPM's sink and relay it into the container stderr with a [php] tag from a best-effort background streamer the entrypoint starts after its init hooks. Also pin down PHP error behaviour: log_errors on, display_errors off (PHP warnings no longer leak into HTTP response bodies), fastcgi.logging off so errors are captured exactly once, and log_limit raised to 8192 so FPM stops truncating PHP stack traces at 1024 chars. The verify suite gains a regression test asserting the marker reaches docker logs.
pcfreak30
force-pushed
the
feat/php-logs-to-container-logging
branch
from
September 25, 2026 00:12
dab61ea to
afe3e55
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves PHP application logs (
error_log(), PHP warnings/errors, captured worker stderr) out of the hidden/var/www/log/php-fpm.logfile into the container's stderr with a[php]line prefix, so Coolifydocker logscarries them for hosting-side troubleshooting. FPM keeps writing the www-data-owned file and a best-effort streamer started by the entrypoint mirrors it; the supervisor and its worker lifecycle are untouched.Pins PHP error behaviour in
php.ini:log_errors=On,display_errors=Off(PHP warnings no longer surface in HTTP response bodies),fastcgi.logging=Offso errors are captured exactly once instead of also reaching Caddy as FastCGI stderr, andlog_limit=8192so FPM stops truncating PHP stack traces at 1024 characters.verify-php-caddy.shgains a regression test: it requests a PHP probe that writes a uniqueerror_log()marker and asserts the line reachesdocker logs.Summary
This pull request streams PHP application logs from the PHP-Caddy workspace images into the container log stream, making them visible through
docker logsand Coolify. Previously, PHP-FPM wrote logs to an internal file that was not surfaced to the orchestrator; now they are relayed to stderr with a recognizable prefix.What changed and why
Log relay in
docker-entrypoint.shA background process is started before dropping privileges that tails
/var/www/log/php-fpm.logand pipes it to the container’s stderr, prefixing each line with[php]. This makes all PHP application logs –error_log()calls, PHP warnings/errors, and worker stderr afterfastcgi_finish_request()– appear indocker logs. The relay is deliberately unsupervised: if it stops, the site keeps serving, and log data is still written to the file, just no longer streamed.PHP-FPM error log configuration (
php-fpm.conf)The existing
error_logfile path is kept as the single sink for PHP logs. The comment explains why a www-data-owned file is used instead of/proc/self/fd/2(the non-root master cannot reliably reopen the root-owned stdout pipe). A newlog_limit = 8192raises the default 1024-character truncation limit for captured worker output, so stack traces and largererror_log()payloads are not cut off.PHP error-handling settings (
php.ini)Added explicit
log_errors = On,display_errors = Off, anddisplay_startup_errors = Off, keeping errors out of HTTP responses and routed only to the container log stream. Also setfastcgi.logging = Offto prevent PHP errors from being forwarded as FastCGI stderr packets and duplicated by Caddy, since FPM already captures them.Documentation (
README.mdandDockerfilecomments)The behavior is documented, including a sample log line, the rationale for the file-based approach, and the fact that errors never leak into HTTP responses and appear exactly once.
Verification script (
scripts/verify-php-caddy.sh)Added an end-to-end check: it creates a PHP file that calls
error_log()with a unique marker, requests it over HTTP, and then asserts the marker appears indocker logs. This ensures the logging contract stays intact in future changes.Impact
Operators can now see PHP application logs directly in
docker logs/ Coolify without needing to exec into a container, with each line tagged[php]. The changes are safe by design – the relay is best-effort and never blocks serving, log lines are no longer truncated, and PHP errors no longer leak into HTTP responses.