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 may be useful if you have short-lived containers.
- Install agent and daemon on the same container. This is the recommended setup.
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-installscript with theinstall_daemonargument. - Start the daemon using
--addressand--watchdog-foregroundarguments.
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
phplikephp:fpmorphp:cli. - To install the agent, download the PHP agent package from New Relic's download site, and run the
newrelic-installscript with theinstallargument. - In the
newrelic.inifile, set the application name and with thenewrelic.appnameandnewrelic.licenseentries . - Point the agent to the daemon by setting the
newrelic.daemon.addressoption in thenewrelic.inifile. Make sure the value for this option isHOST:PORT, whereHOSTis the name or IP address of the host where the daemon is running, andPORTis 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
phplikephp:fpmorphp:cli. - To install the agent, download the PHP agent package from New Relic's download site and run the
newrelic-installscript with theinstallargument. - Set the application name and via the
newrelic.licenseandnewrelic.appnameentries in thenewrelic.inifile.
Tip
Here are some Docker troubleshooting resources: