Per-virtual-host PHP error logs and log rotation

#1
I couldn't find a built-in way to set a different PHP error log path for each virtual host. What I've done is set PHP_INI_SCAN_DIR=:$VH_ROOT/.local/etc/php.d in each Environment setting of the LiteSpeed SAPI App Definitions, then put the following in /var/www/user99/.local/etc/php.d/overrides.ini.
INI:
error_log = /var/www/user99/log/php.log
I can see the correct config setting in the output of PHP info

Now I need to set up rotation for those logs, in case a repeated error ever starts eating up disk space. PHP-FPM accepts a USR1 signal sent to the process in its .pid file(s), but I don't know about LSPHP. I can't see any relevant .pid files on the server, so I guess I have to use killall, but I don't know what signal to use, if any.

Is there a better way to have separate PHP logs? If not, can you confirm the correct method of making LSPHP processes switch to their new log files?
 
#2
@Pong or someone? This is a technical question about LSPHP because its behaviour about log rotation doesn't seem to be documented. It's not about LSWS's log rotation.
 

Pong

Administrator
Staff member
#3
"different PHP error log path for each virtual host", once you setup
error_log = error_log from php.ini, the "error_log" will be generated at each doc_root for each domain already.
 
#4
@Pong Thank you for replying, but as I explained above, I already have different error logs for each virtual host, and they're not exposed into the public in the document root. I wanted to know two things:
  1. If there was was a better, built-in way to set LSPHP's error_log directive in LSWS's GUI, if not that's okay.
  2. What is the official correct way to tell LSPHP that you've rotated its logfile? Log files need rotation. LSWS rotates its own logs but not LSPHP's. Does it accept the same signals as PHP-FPM? Where is this documented?
 

NiteWave

Administrator
#5
What is the official correct way to tell LSPHP that you've rotated its logfile? Log files need rotation. LSWS rotates its own logs but not LSPHP's. Does it accept the same signals as PHP-FPM? Where is this documented?
I think lsws or php process don't have logic to handle the php log rotation.
(no signal needed -- you can just ignore it even when lsws rotates its own logs)

instead, you can use unix/linux's standard logrotate utility which is powerful and can rotate any logs well as you wish.
https://www.tecmint.com/install-logrotate-to-manage-log-rotation-in-linux/
 
#6
I am using logrotate, but normally you send a signal to PHP in the postrotate directive to tell it to use the new inode (same filename). This is because the file covering the previous period gets rotated away, otherwise PHP would keep writing to the old file. Completely restarting PHP is excessive.

I came across the copytruncate directive which should work around the issue.

LSPHP should document what happens if it receives SIGUSR1 and SIGUSR2, even if it's not what people expect.
 
Top