Giter Site home page Giter Site logo

Comments (4)

TrafeX avatar TrafeX commented on June 2, 2024

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

from docker-php-nginx.

gaudinjeremy avatar gaudinjeremy commented on June 2, 2024

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 [email protected]"
LABEL Description="Lightweight container with Nginx 1.24 & PHP 8.2 based on Alpine Linux."

Setup document root

WORKDIR /var/www/html

Install packages and remove default server definition

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

Configure nginx - http

COPY config/nginx.conf /etc/nginx/nginx.conf

Configure nginx - default server

COPY config/conf.d /etc/nginx/conf.d/

Configure PHP-FPM

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

Configure supervisord

COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

Make sure files/folders needed by the processes are accessable when they run under the nobody user

RUN chown -R nobody.nobody /var/www/html /run /var/lib/nginx /var/log/nginx

Create symlink for php

RUN ln -s /usr/bin/php82 /usr/bin/php

ARG NEW_RELIC_LICENSE_KEY="xxxxxxxxxx"
ARG NEW_RELIC_APP_NAME="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}/"
-e "s/;newrelic.enabled =.
/newrelic.enabled = true/"
$PHP_INI_DIR/conf.d/newrelic.ini

Switch to use a non-root user from here on

USER nobody

Add application

COPY --chown=nobody src/ /var/www/html/

Expose the port nginx is reachable on

EXPOSE 8080

Let supervisord start nginx & php-fpm

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

Configure a healthcheck to validate that everything is up&running

HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:8080/fpm-ping
`

Thanks

from docker-php-nginx.

enricodeleo avatar enricodeleo commented on June 2, 2024

@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

from docker-php-nginx.

gaudinjeremy avatar gaudinjeremy commented on June 2, 2024

@enricodeleo

Thanks for the reply, in the meantime I'd found a solution by putting the deamon in another container, which works perfectly.

Best

from docker-php-nginx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.