From 923fdee657060274bb526178acb430c53cee2e5d Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Mon, 18 Aug 2025 21:47:48 +1000 Subject: [PATCH] Fix php logging to STDERR so Docker logs work --- Dockerfile | 4 ++++ app/controllers/app_controller.php | 13 +++++++++++++ conf/apache-vhost.conf | 8 ++++++++ conf/php.ini | 3 ++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7d61532c..45a235d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,5 +57,9 @@ RUN chmod +x /var/www/cmc-sales/run_vault.sh RUN chmod +x /var/www/cmc-sales/run_update_invoices.sh +# Ensure Apache error/access logs go to Docker stdout/stderr +RUN ln -sf /dev/stdout /var/log/apache2/access.log && \ + ln -sf /dev/stderr /var/log/apache2/error.log + # By default, simply start apache. CMD /usr/sbin/apache2ctl -D FOREGROUND diff --git a/app/controllers/app_controller.php b/app/controllers/app_controller.php index b7597452..3eeb28bc 100755 --- a/app/controllers/app_controller.php +++ b/app/controllers/app_controller.php @@ -19,6 +19,9 @@ class AppController extends Controller { $tailscaleName = isset($_SERVER['HTTP_TAILSCALE_USER_NAME']) ? $_SERVER['HTTP_TAILSCALE_USER_NAME'] : null; if ($tailscaleLogin) { + // Log Tailscale authentication attempt + error_log('[TAILSCALE_AUTH] Attempting authentication for: ' . $tailscaleLogin); + // Try to find user by email address from Tailscale header $user = $this->User->find('first', array( 'recursive' => 0, @@ -57,6 +60,9 @@ class AppController extends Controller { 'recursive' => 0, 'conditions' => array('User.id' => $this->User->id) )); + error_log('[TAILSCALE_AUTH] Created new user: ' . $tailscaleLogin); + } else { + error_log('[TAILSCALE_AUTH] Failed to create user: ' . $tailscaleLogin); } } } @@ -64,12 +70,19 @@ class AppController extends Controller { // Fall back to HTTP basic auth if no Tailscale auth or user not found if (!$user && isset($_SERVER["PHP_AUTH_USER"])) { + error_log('[BASIC_AUTH] Attempting authentication for: ' . $_SERVER["PHP_AUTH_USER"]); $user = $this->User->find('first', array( 'recursive' => 0, 'conditions' => array('User.username' => $_SERVER["PHP_AUTH_USER"]) )); } + if ($user) { + error_log('[AUTH_SUCCESS] User authenticated: ' . $user['User']['email']); + } else { + error_log('[AUTH_FAILED] No valid authentication found'); + } + $this->set("currentuser", $user); if($this->RequestHandler->isAjax()) { diff --git a/conf/apache-vhost.conf b/conf/apache-vhost.conf index 7f74ba40..e1820448 100644 --- a/conf/apache-vhost.conf +++ b/conf/apache-vhost.conf @@ -1,4 +1,12 @@ NameVirtualHost *:80 DocumentRoot /var/www/cmc-sales/app/webroot + +# Send Apache logs to stdout/stderr for Docker +ErrorLog /dev/stderr +CustomLog /dev/stdout combined + +# Ensure PHP errors are also logged +php_flag log_errors on +php_value error_log /dev/stderr diff --git a/conf/php.ini b/conf/php.ini index 15a17b3c..9250d1a4 100644 --- a/conf/php.ini +++ b/conf/php.ini @@ -633,7 +633,8 @@ html_errors = Off ; empty. ; http://php.net/error-log ; Example: -error_log = /var/log/php_errors.log +; For Docker: Send errors to stderr so they appear in docker logs +error_log = /dev/stderr ; Log errors to syslog (Event Log on NT, not valid in Windows 95). ;error_log = syslog