AWS Elastic Beanstalk PHP 日志不在 CloudWatch 中

xdh*_*ore 5 php amazon-web-services amazon-cloudwatch amazon-elastic-beanstalk

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

xdh*_*ore 7

根据一些探索,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
Run Code Online (Sandbox Code Playgroud)

根据此处的信息发送到 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
Run Code Online (Sandbox Code Playgroud)

您可以添加自定义配置以使 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
Run Code Online (Sandbox Code Playgroud)

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