简体   繁体   English

AWS Elastic Beanstalk PHP 日志不在 CloudWatch 中

[英]AWS Elastic Beanstalk PHP logs not in CloudWatch

I have a PHP application running via AWS Elastic Beanstalk.我有一个通过 AWS Elastic Beanstalk 运行的 PHP 应用程序。 But the PHP error logs don't seem to be included in CloudWatch alongside the access logs, etc. How do I send them to CloudWatch?但是 PHP 错误日志似乎没有与访问日志等一起包含在 CloudWatch 中。如何将它们发送到 CloudWatch?

Based on some spelunking, the php error logs seem to be sent to /var/logs/php-fpm/www-error.log , decided by the setting in /etc/php-fpm.d/www.conf :基于一些探索,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

The only logs sent to CloudWatch for PHP based on the info here are:根据此处的信息发送到 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

You could add custom configuration to have the CloudWatch agent pick up the correct file.您可以添加自定义配置以使 CloudWatch 代理选取正确的文件。 Or, you could just add the php error messages to a file already being sent.或者,您可以将 php 错误消息添加到已发送的文件中。 This can be done via the following in a file .ebextensions/my.config :这可以通过文件.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

I'm not sure but I think the www-my-overrides.conf file name needs to be alphabetically after www.confg in the same directory.我不确定,但我认为www-my-overrides.conf文件名需要在同一目录中的www.confg之后按字母顺序排列。

If you are using nginx , then you need to use /var/log/nginx/error.log as the error log target -- CloudWatch seems to ignore /var/log/httpd unless you use Apache, so even if you write to it, the changes won't show up in CloudWatch.如果您使用的是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

Additionally, you need to make that file writeable by the php-fpm process which is run as webapp by default, plus you want to make sure it exists ... which it won't yet on new instance creation, so it's very important to do both commands:此外,您需要使默认情况下作为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