Install the PHP agent with Docker

You can install the New Relic PHP agent for APM inside a Docker container to monitor your PHP apps. The PHP agent is only compatible with Docker containers for Linux.


Before beginning this procedure, ensure that you:

Install PHP for Linux Docker containers

To install the PHP agent within a Linux Docker container:

  1. Identify the download URL for the preferred PHP agent package from New Relic's tar file download site.

  2. Create a Dockerfile in your application root.

  3. Edit your Dockerfile. Consider the following example Dockerfile which uses the published Docker image php:7.0.

    Dockerfile example
    FROM php:7.0
    RUN \
      curl -L your_url | tar -C /tmp -zx && \
        NR_INSTALL_USE_CP_NOT_LN=1 NR_INSTALL_SILENT=1 /tmp/newrelic-php5-*/newrelic-install install && \
          rm -rf /tmp/newrelic-php5-* /tmp/nrinstall* && \
            sed -i -e 's/"REPLACE_WITH_REAL_KEY"/"Your License Key"/' \
         -e 's/newrelic.appname = "PHP Application"/newrelic.appname = "Your Application Name"/' \

    There are three places in which you must edit this example Dockerfile to get it to work for you:

    • your_url: the download URL for the desired PHP agent version. Find the most recent version of the agent here:
    • "Your License Key": replace "Your License Key" with your actual New Relic License Key. Note that "REPLACE_WITH_KEY_KEY" is an actual string in the default newrelic.ini file for the PHP Agent. Don't edit that string. The sed command replaces that default string with the actual 40-character key, in quotes.
    • "Your Application Name": replace "Your Application Name" with the desired application name, in quotes.
  4. To finish the installation for Linux Docker containers, build and run the Docker container.

For more help

Recommendations for learning more: