【问题标题】:AWS Elastic Beanstalk PHP logs not in CloudWatchAWS Elastic Beanstalk PHP 日志不在 CloudWatch 中
【发布时间】:2023-04-06 10:26:01
【问题描述】:

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

【问题讨论】:

    标签: php amazon-web-services amazon-elastic-beanstalk amazon-cloudwatch


    【解决方案1】:

    根据一些探索,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
    

    根据here 信息发送到 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 之后按字母顺序排列。

    【讨论】:

      【解决方案2】:

      如果您使用nginx,那么您需要使用/var/log/nginx/error.log 作为错误日志目标——CloudWatch 似乎会忽略/var/log/httpd,除非您使用 Apache,因此即使您写入它,更改也不会'不会出现在 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
      

      此外,您需要使该文件可被 php-fpm 进程写入,该进程默认以webapp 运行,此外您还想确保它存在......它不会在创建新实例时,所以执行这两个命令非常重要:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-18
        • 2017-11-05
        • 2019-02-11
        • 2015-01-14
        • 2017-09-19
        • 2020-05-26
        • 2022-09-26
        • 2019-01-23
        相关资源
        最近更新 更多