Open gaudinjeremy opened 4 months ago
Hi @gaudinjeremy,
Try this, this works for me:
# New Relic settings
ARG NEW_RELIC_LICENSE_KEY="your-license-key"
ARG NEW_RELIC_APP_NAME="your-app-name"
# Install New Relic
RUN mkdir -p /var/log/newrelic /var/run/newrelic && \
touch /var/log/newrelic/php_agent.log /var/log/newrelic/newrelic-daemon.log && \
chmod -R g+ws /tmp /var/log/newrelic/ /var/run/newrelic/ && \
chown -R 1001:0 /tmp /var/log/newrelic/ /var/run/newrelic/ && \
# Download and install Newrelic binary
export NEWRELIC_VERSION=$(curl -sS https://download.newrelic.com/php_agent/release/ | sed -n 's/.*>\(.*linux\).tar.gz<.*/\1/p') && \
cd /tmp && curl -sS "https://download.newrelic.com/php_agent/release/${NEWRELIC_VERSION}.tar.gz" | gzip -dc | tar xf - && \
cd "${NEWRELIC_VERSION}" && \
NR_INSTALL_SILENT=true ./newrelic-install install && \
rm -f /var/run/newrelic-daemon.pid && \
rm -f /tmp/.newrelic.sock && \
sed -i \
-e "s/newrelic.license =.*/newrelic.license = ${NEW_RELIC_LICENSE_KEY}/" \
-e "s/newrelic.appname =.*/newrelic.appname = ${NEW_RELIC_APP_NAME}/" \
$PHP_INI_DIR/conf.d/newrelic.ini
Thanks @TrafeX,
The installation has been completed, but I haven't received any data from Newrelic.
I modified the code by adding this line to activate newrelic : "-e "s/;newrelic.enabled =.*/newrelic.enabled = true/" \"
but this had no effect.
Here's my complete dockerfile
`ARG ALPINE_VERSION=3.18 FROM --platform=linux/amd64 alpine:${ALPINE_VERSION} LABEL Maintainer="Tim de Pater code@trafex.nl" LABEL Description="Lightweight container with Nginx 1.24 & PHP 8.2 based on Alpine Linux."
WORKDIR /var/www/html
RUN apk add --no-cache \ curl \ nginx \ php82 \ php82-ctype \ php82-curl \ php82-dom \ php82-fileinfo \ php82-fpm \ php82-gd \ php82-intl \ php82-mbstring \ php82-mysqli \ php82-opcache \ php82-openssl \ php82-phar \ php82-session \ php82-tokenizer \ php82-xml \ php82-xmlreader \ php82-xmlwriter \ php82-redis \ supervisor
COPY config/nginx.conf /etc/nginx/nginx.conf
COPY config/conf.d /etc/nginx/conf.d/
ENV PHP_INI_DIR /etc/php82 COPY config/fpm-pool.conf ${PHP_INI_DIR}/php-fpm.d/www.conf COPY config/php.ini ${PHP_INI_DIR}/conf.d/custom.ini
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN chown -R nobody.nobody /var/www/html /run /var/lib/nginx /var/log/nginx
RUN ln -s /usr/bin/php82 /usr/bin/php
ARG NEW_RELIC_LICENSE_KEY="xxxxxxxxxx" ARG NEW_RELIC_APP_NAME="app_name"
RUN mkdir -p /var/log/newrelic /var/run/newrelic && \ touch /var/log/newrelic/php_agent.log /var/log/newrelic/newrelic-daemon.log && \ chmod -R g+ws /tmp /var/log/newrelic/ /var/run/newrelic/ && \ chown -R 1001:0 /tmp /var/log/newrelic/ /var/run/newrelic/ && \
export NEWRELIC_VERSION=$(curl -sS https://download.newrelic.com/php_agent/release/ | sed -n 's/.*>\(.*linux\).tar.gz<.*/\1/p') && \
cd /tmp && curl -sS "https://download.newrelic.com/php_agent/release/${NEWRELIC_VERSION}.tar.gz" | gzip -dc | tar xf - && \
cd "${NEWRELIC_VERSION}" && \
NR_INSTALL_SILENT=true ./newrelic-install install && \
rm -f /var/run/newrelic-daemon.pid && \
rm -f /tmp/.newrelic.sock && \
sed -i \
-e "s/newrelic.license =.*/newrelic.license = ${NEW_RELIC_LICENSE_KEY}/" \
-e "s/newrelic.appname =.*/newrelic.appname = ${NEW_RELIC_APP_NAME}/" \
-e "s/;newrelic.enabled =.*/newrelic.enabled = true/" \
$PHP_INI_DIR/conf.d/newrelic.ini
USER nobody
COPY --chown=nobody src/ /var/www/html/
EXPOSE 8080
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:8080/fpm-ping `
Thanks
@gaudinjeremy this is the relevant code you need to add to your Dockerfile (discarding your previously implementation of APM). It is tested working on trafex/php-nginx:3.4.0
.
Of course you need to build the image with the right --args
and make sure the NEW_RELIC_DAEMON_ADDRESS
is correct and reachable from the container once running (e.g. being on the same docker network or both being bound to host).
# Configure New Relic
ARG NEW_RELIC_LICENSE_KEY
ARG NEW_RELIC_APP_NAME
ARG NEW_RELIC_DAEMON_ADDRESS
ENV NEW_RELIC_LICENSE_KEY ${NEW_RELIC_LICENSE_KEY}
ENV NEW_RELIC_APP_NAME ${NEW_RELIC_APP_NAME}
ENV NEW_RELIC_DAEMON_ADDRESS ${NEW_RELIC_DAEMON_ADDRESS}
# Install New Relic PHP Agent BEFORE SWITCHING USER to nobody
RUN mkdir -p /var/log/newrelic /var/run/newrelic && \
touch /var/log/newrelic/php_agent.log /var/log/newrelic/newrelic-daemon.log && \
chmod -R g+ws /tmp /var/log/newrelic/ /var/run/newrelic/ && \
chown -R 1001:0 /tmp /var/log/newrelic/ /var/run/newrelic/ && \
# Download and install Newrelic binary
export NEWRELIC_VERSION=$(curl -sS https://download.newrelic.com/php_agent/release/ | sed -n 's/.*>\(.*linux\).tar.gz<.*/\1/p') && \
cd /tmp && curl -sS "https://download.newrelic.com/php_agent/release/${NEWRELIC_VERSION}.tar.gz" | gzip -dc | tar xf - && \
cd "${NEWRELIC_VERSION}" && \
NR_INSTALL_SILENT=true ./newrelic-install install && \
rm -f /var/run/newrelic-daemon.pid && \
rm -f /tmp/.newrelic.sock && \
sed -i \
-e "s/newrelic.license =.*/newrelic.license = ${NEW_RELIC_LICENSE_KEY}/" \
-e "s/newrelic.appname =.*/newrelic.appname = ${NEW_RELIC_APP_NAME}/" \
-e "s/;newrelic.enabled = true/newrelic.enabled = true/" \
-e "s/;newrelic.daemon.address =.*/newrelic.daemon.address = \"${NEW_RELIC_DAEMON_ADDRESS}:31339\"/" \
$PHP_INI_DIR/conf.d/newrelic.ini
@enricodeleo
Thanks for the reply, in the meantime I'd found a solution by putting the deamon in another container, which works perfectly.
Best
Hello,
I tried to add the newrelic APM for php but I get this error:
It seems to be a file path problem linked to this line "0.760 sed: /usr/local/etc/php82/conf.d/newrelic.ini: No such file or directory" but even by changing the directories I haven't managed to finalize the installation.
I followed the newrelic doc to install (https://docs.newrelic.com/docs/apm/agents/php-agent/advanced-installation/docker-other-container-environments-install-php-agent/#install-diff-containers)
Thanks