简体   繁体   中英

AWS Elastic Beanstalk PHP logs not in CloudWatch

I have a PHP application running via AWS Elastic Beanstalk. 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?

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_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:

/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. Or, you could just add the php error messages to a file already being sent. This can be done via the following in a file .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.

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.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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