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.
Tip
To use PHP or any other agent, as well as the rest of our observability platform, join the New Relic family! Sign up to create your free account in only a few seconds. Then ingest up to 100GB of data for free each month. Forever.
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
Requirements:
- Meet PHP agent requirements
- PHP agent version 9.2 or higher
To see an example application, go to New Relic's Explorers Hub.
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 published Docker image like
php:7.1
. - To install the agent, download the PHP agent package from New Relic's tar file download site, and run the
newrelic-install
script with theinstall
argument. - In the
newrelic.ini
file, set the application name and license key 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
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: you might use a published Docker image like
php:7.1
. - To install the agent, download the PHP agent package from New Relic's tar file download site and run the
newrelic-install
script with theinstall
argument. - Set the application name and license key via the
newrelic.license
andnewrelic.appname
entries in thenewrelic.ini
file. - By default, the first transaction causes the agent to trigger a daemon start and an application connection initialization. However, for performance reasons, the agent does not wait for those operations to complete before it initializes the connection, which can result in the loss of the first few transactions after a container starts. To prevent this, set both
newrelic.daemon.start_timeout
andnewrelic.daemon.app_connect_timeout
entries in thenewrelic.ini
file to recommended values.
For more help
If you need more help, check out these support and learning resources:
- Suggest a change and learn how to contribute to our PHP agent open source repository.
- Browse the Explorers Hub to get help from the community and join in discussions.
- Find answers on our sites and learn how to use our support portal.
- Run New Relic Diagnostics, our troubleshooting tool for Linux, Windows, and macOS.
- Review New Relic's data security and licenses documentation.