Install the PHP agent with Docker

You can install the New Relic PHP agent for APM inside a Docker container in order 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 this example Dockerfile, which uses the published Docker image php:7.0.

    Dockerfile example
    FROM php:7.0
    RUN \
      curl -L PHP_AGENT_URL | tar -C /tmp -zx && \
       export NR_INSTALL_USE_CP_NOT_LN=1 && \
        export 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:

    • PHP_AGENT_URL: The download URL for the desired PHP agent version. Find the most recent version of the agent here:
    • YOUR_LICENSE_KEY: Replace this with your New Relic license key. Note that "REPLACE_WITH_REAL_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 this 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: