0

I am trying to find a solution for getting logs from php72 php-fpm yii2 application behind nginx on several numbers of servers: at now application writes its logs to files on server disk, yii performs rotation of log files.

But this solution requires fast and large disks that costs $$ and getting logs in one place with shared dir - another problem because acessing files from several servers causes individual log lines to be fragmented.

At the moment I began using promtail/loki, but promtail need to be running on the server with application and gives additional overhead for configuration and operate.

Here comes (I was thought) old good rsyslog, but all my attempts to get access logs from php-fpm failed:

  • getting all rsyslog lines to central promtail, not without problems, but it works,
  • getting log to rsyslog from pure php-cli scripts - ok,
  • yii-scripts - some lack of succes,
  • php-fpm - no one: no access logs, no error logs dont get to (r)syslog

what I relied on:

https://www.yiiframework.com/doc/api/2.0/yii-log-syslogtarget#$levels-detail

https://bugs.php.net/bug.php?id=76229

https://bugs.php.net/bug.php?id=67764

https://bugs.php.net/bug.php?id=79342

nginx / php-fpm error logging

My configs:

/etc/php.ini

;error_log = syslog # if change fpm writes nothing to syslog 

/etc/php-fpm.conf

error_log = syslog syslog.facility = local0 syslog.ident = php-fpm log_level = notice # debug mode results in a constant stream of lines about child processes spawning 

/etc/php-fpm.d/site.conf

php_admin_flag[log_errors] = on php_admin_value[auto_prepend_file] = /etc/php-fpm.d/prepare_log.php ;php_admin_value[syslog.facility] = local0 # if uncomment php cannot change admin flag value ;php_admin_value[syslog.ident] = php-fpm-$pool # if uncomment php cannot change admin flag value access.log = syslog slowlog = syslog ;php_admin_value[error_log] = /var/log/php-fpm/$pool-error.log ;php_admin_value[error_log] = syslog # if uncomment php cannot change admin flag value 

/etc/php-fpm.d/prepare_log.php

<?php openlog('php', LOG_NOTICE, LOG_LOCAL3); 

/etc/rsyslog.conf

$ModLoad imuxsock $ModLoad imjournal ... *.* action(type="omfwd" protocol="tcp" target="promtail.localdomain" port="1514" Template="RSYSLOG_SyslogProtocol23Format" TCP_Framing="octet-counted" KeepAlive="on") 

There is exists any solutions for such problem without writing logs to the files and read from them? Maybe I dont get things right, maybe I need to look at docker/kubernetes mechanics to get logs, maybe there is a library to write directly to syslog/promtail that doesn't require a lot of application code change

1 Answer 1

0

As I understand, access.log can't write logs to (r)syslog directly. I met this problem last week and solved it by writing PHP-FPM logs to file and reading them by rsyslog. But I see that solution doesn't fit to your case :(

I also saw some socket extensions for rsyslog and maybe you could somehow read logs from /proc/self/fd. I tried to do this but it wasn't successful and I had to be content with solution above.

Also sorry for my bad English :)

2
  • Btw, if you have already solved that problem, I'm very intersted to know how you did it Commented Aug 15, 2024 at 15:59
  • I used promtail (vector.dev later) to read files on server at that moment, after that I red some variants with /dev/log (and reading from journald) and file descriptors which opened by vector.dev. but that time I forget about opened question =) Commented Aug 16, 2024 at 17:33

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.