Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Relic Solution: Keeping the PHP Agent up to date in Containerised Applications

level-up

#1

When installing the New Relic PHP Agent within Docker, our installation documentation provides an example Dockefile which downloads the latest PHP agent package from New Relic’s tar file download site:

FROM php:7.1

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"/' \
      -e 's/;newrelic.daemon.app_connect_timeout =.*/newrelic.daemon.app_connect_timeout=15s/' \
      -e 's/;newrelic.daemon.start_timeout =.*/newrelic.daemon.start_timeout=5s/' \
      /usr/local/etc/php/conf.d/newrelic.ini

The PHP_AGENT_URLvariable is the URL defined by the user for their desired PHP agent version they wish to download. The documentation provides a link to the most recent release of the Agent.

An issue here is that once the PHP agent is updated, the Dockerfile build will fail due to the latest release of the PHP agent being found here while the archived versions of the PHP agent being found here. Another issue is that the user will need to manually insert the new download URL each time a new Agent version is released.

If you like to keep up to date with the releases of the PHP Agent in your containerised application, one workaround here is to use curl to fetch the HTML content and then use sed to grab the most recent release version number from the HTML source.

RUN \
  export NR_VERSION=$(curl -sS https://download.newrelic.com/php_agent/release/ | sed -n 's/.*>\(.*linux\).tar.gz<.*/\1/p') && \
  curl -L http://download.newrelic.com/php_agent/release/${NR_VERSION}.tar.gz | tar -C /tmp -zx

Please note that this workaround could break if New Relic change the structure of the tar download website.