Skip to content

feat(workspaces): stream PHP application logs to the container log stream - #11

Merged
pcfreak30 merged 1 commit into
developfrom
feat/php-logs-to-container-logging
Sep 25, 2026
Merged

pcfreak30 merged 1 commit into
developfrom
feat/php-logs-to-container-logging

Conversation

@pcfreak30

@pcfreak30 pcfreak30 commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Moves PHP application logs (error_log(), PHP warnings/errors, captured worker stderr) out of the hidden /var/www/log/php-fpm.log file into the container's stderr with a [php] line prefix, so Coolify docker logs carries 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=Off so errors are captured exactly once instead of also reaching Caddy as FastCGI stderr, and log_limit=8192 so FPM stops truncating PHP stack traces at 1024 characters.

verify-php-caddy.sh gains a regression test: it requests a PHP probe that writes a unique error_log() marker and asserts the line reaches docker 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 logs and 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.sh
    A background process is started before dropping privileges that tails /var/www/log/php-fpm.log and 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 after fastcgi_finish_request() – appear in docker 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_log file 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 new log_limit = 8192 raises the default 1024-character truncation limit for captured worker output, so stack traces and larger error_log() payloads are not cut off.

  • PHP error-handling settings (php.ini)
    Added explicit log_errors = On, display_errors = Off, and display_startup_errors = Off, keeping errors out of HTTP responses and routed only to the container log stream. Also set fastcgi.logging = Off to prevent PHP errors from being forwarded as FastCGI stderr packets and duplicated by Caddy, since FPM already captures them.

  • Documentation (README.md and Dockerfile comments)
    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 in docker 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.

@kody-ai

kody-ai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

​

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
pcfreak30 force-pushed the feat/php-logs-to-container-logging branch from dab61ea to afe3e55 Compare September 25, 2026 00:12
@pcfreak30
pcfreak30 merged commit 9c5d348 into develop Sep 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant