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 the standard PHP agent compatibility and requirements.
Important
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 on different containers. This is the recommended setup.
- Install agent and daemon on the same container. This may be useful if you want to reduce your number of containers.
Install agent and daemon in different containers
Installing the agent and daemon in different containers is supported starting with New Relic PHP agent release 9.2.0.
To see an example application, go to New Relic's Support Forum. 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:
- Run this command:
docker pull newrelic/php-daemon
. - To customize the image, follow the steps on Docker Hub.
You can also build your own daemon image:
- To install the daemon, download the PHP agent package from New Relic's tar file download site, and run the
newrelic-install
script with theinstall_daemon
argument. - 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:
- Make sure a PHP installation is available in the container. For example, use a Docker "Official Image" for
php
likephp:fpm
orphp:cli
. - To install the agent, download the PHP agent package from New Relic's download site, and run the
newrelic-install
script with theinstall
argument. - In the
newrelic.ini
file, set the application name and with thenewrelic.appname
andnewrelic.license
entries . - Point the agent to the daemon by setting the
newrelic.daemon.address
option in thenewrelic.ini
file. Make sure the value for this option isHOST:PORT
, whereHOST
is the name or IP address of the host where the daemon is running, andPORT
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 of 5s and 15s respectively.
To set up the PHP agent and daemon in the same Docker container:
- Make sure a PHP installation is available in the container. For example, use a Docker "Official Image" for
php
likephp:fpm
orphp:cli
. - To install the agent, download the PHP agent package from New Relic's download site and run the
newrelic-install
script with theinstall
argument. - Set the application name and via the
newrelic.license
andnewrelic.appname
entries in thenewrelic.ini
file.
Tip
Here are some Docker troubleshooting resources: