From 6f161ed0059109fc87437ac43e54fecb2a380888 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 20 Nov 2026 06:43:41 +0530 Subject: [PATCH] feat(php): enable the New Relic agent on PHP 8.5 The New Relic PHP agent 12.13.0.43 ships newrelic-20250925.so, PHP 8.5's module API, so the PHP 8.5 image installs it the same way as 8.4: the agent install step with the tarball-only download grep from #384, NR_PORT, newrelic.ini in conf.d and in /data, and the entrypoint that writes NEWRELIC_LICENSE_KEY and NEWRELIC_APPNAME into it. newrelic is added to the module guard list. The 8.5 entrypoint copies /data/newrelic.ini into conf.d when a key is set and the file is missing, and only warns when it can't write it. A site's php config comes from the image only when its volume is first created; after `ee site update --php` it comes from site-command's php-fpm zip, which has no newrelic.ini, and every existing 8.5 site was created from an image without it. With 8.4's entrypoint, setting a key on such a site makes sed fail under `set -e` and the php container exits before php-fpm starts. Without a key, the entrypoint behaves exactly like 8.4's. --- php/8.5/Dockerfile | 20 ++++++++++---------- php/8.5/docker-entrypoint.sh | 21 ++++++++++++++------- php/8.5/expected-modules.txt | 1 + 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/php/8.5/Dockerfile b/php/8.5/Dockerfile index c389558..f391691 100644 --- a/php/8.5/Dockerfile +++ b/php/8.5/Dockerfile @@ -121,14 +121,14 @@ ln -s /usr/local/etc/misc/msmtprc /etc/msmtprc && \ chown www-data:www-data /usr/local/etc/misc/msmtprc && \ chown www-data:www-data /etc/msmtprc -#RUN latest_build=$(curl -s https://download.newrelic.com/php_agent/release/ | grep 'linux\.tar\.gz"' | head -n 1 | sed 's/.*"\(.*\)".*/\1/') && \ -#curl -L "https://download.newrelic.com$latest_build" | 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* -# -#ENV NR_PORT=/run/newrelic/newrelic.sock +RUN latest_build=$(curl -s https://download.newrelic.com/php_agent/release/ | grep 'linux\.tar\.gz"' | head -n 1 | sed 's/.*"\(.*\)".*/\1/') && \ +curl -L "https://download.newrelic.com$latest_build" | 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* + +ENV NR_PORT=/run/newrelic/newrelic.sock # Setup logs RUN mkdir -p /var/log/php; \ @@ -141,8 +141,8 @@ COPY expose_off.ini /usr/local/etc/php/conf.d/expose_off.ini COPY bashrc /root/.bashrc COPY bashrc /var/www/.bashrc COPY docker-entrypoint.sh /usr/local/bin/ -#COPY newrelic.ini /usr/local/etc/php/conf.d/newrelic.ini -#COPY newrelic.ini /data/newrelic.ini +COPY newrelic.ini /usr/local/etc/php/conf.d/newrelic.ini +COPY newrelic.ini /data/newrelic.ini WORKDIR /var/www/htdocs RUN usermod -s /bin/bash www-data diff --git a/php/8.5/docker-entrypoint.sh b/php/8.5/docker-entrypoint.sh index fc68270..7e0ca41 100755 --- a/php/8.5/docker-entrypoint.sh +++ b/php/8.5/docker-entrypoint.sh @@ -1,12 +1,19 @@ #!/bin/bash set -euo pipefail -o nounset -#if [[ -z "${NEWRELIC_LICENSE_KEY:-}" ]] || [[ -z "${NEWRELIC_APPNAME:-}" ]]; then -# : -#else -# sed -i -e "s/\"REPLACE_WITH_REAL_KEY\"/\"$NEWRELIC_LICENSE_KEY\"/" \ -# -e "s/newrelic.appname = \"PHP Application\"/newrelic.appname = \"$NEWRELIC_APPNAME\"/" \ -# /usr/local/etc/php/conf.d/newrelic.ini -#fi +nr_ini=/usr/local/etc/php/conf.d/newrelic.ini +if [[ -z "${NEWRELIC_LICENSE_KEY:-}" ]] || [[ -z "${NEWRELIC_APPNAME:-}" ]]; then + : +else + # A site config made from a php-fpm zip (ee site update --php) has no newrelic.ini: start from the image's copy instead of failing. + if [[ ! -f "$nr_ini" ]] && ! cp /data/newrelic.ini "$nr_ini"; then + echo "docker-entrypoint: could not create $nr_ini, New Relic stays off" >&2 + fi + if [[ -f "$nr_ini" ]]; then + sed -i -e "s/\"REPLACE_WITH_REAL_KEY\"/\"$NEWRELIC_LICENSE_KEY\"/" \ + -e "s/newrelic.appname = \"PHP Application\"/newrelic.appname = \"$NEWRELIC_APPNAME\"/" \ + "$nr_ini" || echo "docker-entrypoint: could not write the New Relic license to $nr_ini" >&2 + fi +fi exec "$@" diff --git a/php/8.5/expected-modules.txt b/php/8.5/expected-modules.txt index c3a3421..38489e5 100644 --- a/php/8.5/expected-modules.txt +++ b/php/8.5/expected-modules.txt @@ -24,6 +24,7 @@ mcrypt memcached mysqli mysqlnd +newrelic openssl pcntl pcre