为什么 PHP 错误的记录会停止?

Why would logging of PHP errors stop?

在 Centos 上将 Plesk 与 Apache 和 Nginx 一起使用。

正在完美地记录错误;

/var/www/vhosts/example.com/logs/error_log

/var/www/vhosts/example.com/logs/proxy_error_log

我通过删除并重新创建文件来截断文件;现在什么都没有记录。文件所有者和文件权限都相同;但错误记录刚刚停止。

我检查了其他域,它们都按预期完美运行。

实际上网络服务器日志存储在 /var/www/vhosts/system/example.tld/logs/.

/var/www/vhosts/example.tld/logs/ 中的日志文件它不是文件,而是 /var/www/vhosts/system/example.tld/logs/ 中文件的硬链接。注意相同的 inode 编号 261064:

# ls -lia /var/www/vhosts/example.tld/logs/error_log
261064 -rw-r--r--. 2 root root 2432 Jun  8 18:26 /var/www/vhosts/example.tld/logs/error_log
# ls -lia /var/www/vhosts/system/example.tld/logs/error_log
261064 -rw-r--r--. 2 root root 2432 Jun  8 18:26 /var/www/vhosts/system/example.tld/logs/error_log

当我删除这个文件时,我也删除了硬链接:

# rm /var/www/vhosts/example.tld/logs/error_log
rm: remove regular file `/var/www/vhosts/example.tld/logs/error_log'? y
# ls -lia /var/www/vhosts/system/example.tld/logs/error_log
261064 -rw-r--r--. 1 root root 2432 Jun  8 18:26 /var/www/vhosts/system/example.tld/logs/error_log

当我再次创建它时,它将拥有自己的 inode 编号 (276777):

# touch /var/www/vhosts/example.tld/logs/error_log
# ls -lia /var/www/vhosts/example.tld/logs/error_log
276777 -rw-r--r--. 1 root root 0 Jun  8 18:33 /var/www/vhosts/example.tld/logs/error_log

所以要解决您的问题,您只需要删除您创建的文件并创建硬链接到 system/log 中的文件:

# rm /var/www/vhosts/example.tld/logs/error_log
# ln /var/www/vhosts/system/example.tld/logs/error_log /var/www/vhosts/example.tld/logs/error_log
# ls -lia /var/www/vhosts/example.tld/logs/error_log
261064 -rw-r--r--. 2 root root 2432 Jun  8 18:33 /var/www/vhosts/example.tld/logs/error_log

服务器可能仍在尝试写入您删除的文件。重启 nginx 和 apache。