• Log inFree account

Docker and other container environments: Install PHP agent

You can install the PHP agent on a Docker container or other container to monitor one or more of your PHP applications. This is supported for containers that meet PHP agent requirements.

Caution

The PHP Agent's daemon transmits data to New Relic periodically during the minute-long harvest cycle. If you're starting up and tearing down containers often, ensure that you leave the daemon container running long enough to transmit any remaining data.

Container options

The PHP agent requires two components to work: the PHP agent (one for each application) and a daemon, which aggregates data sent from one or more agents and sends it to New Relic. For this reason, there are two options for enabling the PHP agent for container environments:

Install agent and daemon in different containers

Requirements:

To see an example application, go to New Relic's Explorers Hub. If you're using short-lived application containers, we recommend you use a separate container for the PHP Agent's daemon.

Caution

Data transmitted from the agent to the daemon is not encrypted. The only exception to this is the SQL obfuscation that happens before sending data to the daemon. If the agent and daemon are running on different hosts, we recommend that you use a private network connection between the agent and daemon.

Set up the daemon container

If you use Docker, you can pull our daemon image from Docker Hub:

  1. Run this command: docker pull newrelic/php-daemon.
  2. To customize the image, follow the steps on Docker Hub.

You can also build your own daemon image:

  1. To install the daemon, download the PHP agent package from New Relic's tar file download site, and run the newrelic-install script with the install_daemon argument.
  2. Start the daemon using --address and --watchdog-foreground arguments.

The --address argument sets a port for the daemon to accept connections. The --watchdog-foreground argument ensures that the daemon runs in the foreground.

Set up the PHP agent container

To set up the PHP agent container for Docker:

  1. Make sure a PHP installation is available in the container. For example, use a published Docker image like php:7.1.
  2. To install the agent, download the PHP agent package from New Relic's tar file download site, and run the newrelic-install script with the install argument.
  3. In the newrelic.ini file, set the application name and license key with the newrelic.appname and newrelic.license entries .
  4. Point the agent to the daemon by setting the newrelic.daemon.address option in the newrelic.ini file. Make sure the value for this option is HOST:PORT, where HOST is the name or IP address of the host where the daemon is running, and PORT is the port number where the daemon is listening

Install agent and daemon in the same container

Caution

By default, the first transaction causes the agent to trigger a daemon start and an application connection initialization. For performance reasons, the agent does not wait for those operations to complete before it initializes the connection. This can result in the loss of the first few transactions after a container starts. To prevent this loss, set both newrelic.daemon.start_timeout and newrelic.daemon.app_connect_timeout entries in the newrelic.ini file to our (recommended values)[https://discuss.newrelic.com/t/php-troubleshooting-framework-configuration/119980] of 5s and 15s respectively.

To set up the PHP agent and daemon in the same Docker container:

  1. Make sure a PHP installation is available in the container. For example: you might use a published Docker image like php:7.1.
  2. To install the agent, download the PHP agent package from New Relic's tar file download site and run the newrelic-install script with the install argument.
  3. Set the application name and license key via the newrelic.license and newrelic.appname entries in the newrelic.ini file.

callout.info

Here are some Docker troubleshooting resources:

Copyright © 2022 New Relic Inc.