'Make PHP error logs available to CloudWatch and logs bundle

I have a PHP environment in my ElasticBeanstalk application. I receive a HTTP 500 error at some point and I am unable to debug it as I don't see any log of it in the logs bundle. My environment is configured to stream logs to CloudWatch and still nothing about the 500 error.

I tried adding a configuration file to the .ebextensions directory:

files:
  "/opt/elasticbeanstalk/tasks/bundlelogs.d/php.conf":
    mode: "000755"
    owner: root
    group: root
    content: |
      /var/log/php/*
      /var/log/php-fpm/*

But still there is no php log file in the logs bundle. What can I do about this? Thanks.



Solution 1:[1]

IF you are using a php framework, most of them are configured to intercept and handle errors, so they don't show up in standard logs.

For Laravel, you would need to make sure you have logging enabled, and either set or use the default log location, and then add that location to your configuration.

See Where are logs located? for more information on logging.

Solution 2:[2]

The following is not tested, but should hopefully do the trick.

We should first start with finding where exactly the logs are located (see Where are logs located?). Once we identify that, we note the following (from the AWS docs):

The Elastic Beanstalk integration with CloudWatch Logs doesn't directly support the streaming of custom log files that your application generates. To stream custom logs, use a configuration file to directly install the CloudWatch Logs agent and to configure the files to be pushed.

Example configuration also given in the docs can be found here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chris
Solution 2 Victor