(This is a general question on Caddy’s operation and isn’t relevant to a specific configuration, therefore I’m skipping the template. If this information is still required, let me know.)
I’m migrating a PHP based website from caddy v1 to v2. v1 had an errors directive, which allowed you to have a separate log of PHP errors into the log file configured with the errors directive. (Although I’m not exactly sure, I believe technically these are fastcgi stderr logs.)
While translating the above to v2, I wasn’t able to find a similar directive to log errors, and the access logs apparently do not contain these logs either.
So, is there an alternative to the errors directive that would allow me to have a log of errors from PHP? I’m also fine with logging these errors within access logs as long as they can be made to appear in the same log entry as the request.
errors never contained errors from PHP, it was always errors emitted by Caddy itself. Your PHP-FPM service should be logging its own errors.
The relevant reading regarding logging in v2 is this document:
Caddy emits logs to stdout and stderr by default, and you can configure an alternate log writer via global options if you prefer. If you’re running Caddy as a systemd service, you probably don’t need to do this, because you can run journalctl -u caddy --no-pager | less to see the logs.
I double-checked my website on v1 and these logs are in fact being written by caddy, and PHP has never been configured to write logs of any kind. Here’s a sample of logs that are being written by Caddy and they appear to be logged by this line in v1:
02/Jul/2021:15:25:40 +0000 [ERROR 0 /index.php] PHP message: PDOException: SQLSTATE[22001]: String data, right truncated: 7 ERROR: value too long for type character varying(255) in /var/www/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php
02/Jul/2021:20:52:58 +0000 [ERROR 504 /index.php] read unix @->/run/php/php7.4-fpm.sock: i/o timeout
03/Jul/2021:09:59:37 +0000 [ERROR 504 /index.php] read unix @->/run/php/php7.4-fpm.sock: i/o timeout
03/Jul/2021:15:25:06 +0000 [ERROR 504 /index.php] read unix @->/run/php/php7.4-fpm.sock: i/o timeout
The later part of your reply doesn’t seem to mention if this error logging functionality has been kept or removed, so I take it that it has been removed?