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.

Requirements

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.

    1. 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 your_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"/' \
               /usr/local/etc/php/conf.d/newrelic.ini
              

      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: https://download.newrelic.com/php_agent/release/
      • 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.
  3. To finish the installation for Linux Docker containers, build and run the Docker container.

For more help

Recommendations for learning more: