繁体   English   中英

AWS Elastic Beanstalk PHP 日志不在 CloudWatch 中

[英]AWS Elastic Beanstalk PHP logs not in CloudWatch

我有一个通过 AWS Elastic Beanstalk 运行的 PHP 应用程序。 但是 PHP 错误日志似乎没有与访问日志等一起包含在 CloudWatch 中。如何将它们发送到 CloudWatch?

基于一些探索,php 错误日志似乎被发送到/var/logs/php-fpm/www-error.log ,由/etc/php-fpm.d/www.conf的设置决定:

php_admin_value[error_log] = /var/log/php-fpm/www-error.log

根据此处的信息发送到 CloudWatch for PHP 的唯一日志是:

/var/log/eb-engine.log
/var/log/eb-hooks.log
/var/log/httpd/access_log
/var/log/httpd/error_log
/var/log/nginx/access.log
/var/log/nginx/error.log

您可以添加自定义配置以使 CloudWatch 代理选取正确的文件。 或者,您可以将 php 错误消息添加到已发送的文件中。 这可以通过文件.ebextensions/my.config的以下内容完成:

/etc/php-fpm.d/www-my-overrides.conf:
  mode: "000644"
  owner: root
  group: root
  # For some reason, EB configures the php errors to go to /var/log/php-fpm/www-error.log,
  # but doesn't include that file in the default log files sent to CloudWatch. This directs
  # the log files to the error file that is being sent to CloudWatch
  content: |
    [www]
    php_admin_value[error_log] = /var/log/httpd/error_log

我不确定,但我认为www-my-overrides.conf文件名需要在同一目录中的www.confg之后按字母顺序排列。

如果您使用的是nginx ,那么您需要使用/var/log/nginx/error.log作为错误日志目标——除非您使用 Apache,否则 CloudWatch 似乎会忽略/var/log/httpd ,因此即使您写入它,更改不会显示在 CloudWatch 中。

files:
  /etc/php-fpm.d/www-my-overrides.conf:
    mode: "000644"
    owner: root
    group: root
    # For some reason, EB configures the php errors to go to /var/log/php-fpm/www-error.log,
    # but doesn't include that file in the default log files sent to CloudWatch. This directs
    # the log files to the error file that is being sent to CloudWatch
    content: |
      [www]
      php_admin_value[error_log] = /var/log/nginx/error.log

此外,您需要使默认情况下作为webapp运行的 php-fpm 进程可写入该文件,此外您还想确保它存在......它不会在新实例创建时出现,因此非常重要执行两个命令:

container_commands:
  01-command:
    command: echo "-- DEPLOYMENT --" >> /var/log/nginx/error.log
  02-command:
    command: chmod 666 /var/log/nginx/error.log

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM