Comments (5)
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.
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.
@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.
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.
Sounds like this is resolved 👍
from docker-php-nginx.
Related Issues (20)
- [Question] Turn off "nobody" user HOT 10
- Weird Issue with Volumes. HOT 4
- Unable to set custom DNS HOT 2
- Add php_ldap HOT 1
- supervisorctl not working HOT 2
- Optimize PHP-FPM with JIT HOT 3
- Clean up nginx config HOT 2
- vscode-server` HOT 4
- docker-php-nginx with PHP 8.3? HOT 1
- application/javascript mime type is missing in gzip_types HOT 1
- image Performing a pressure test using Apache Benchmark (ab). HOT 1
- installing php extensions HOT 1
- Weird PSR-7 request target for current nginx default.conf with path info HOT 1
- Version mismatch (latest !=3.5.0 HOT 3
- I cannot run commands like "composer install" when using Windows WSL HOT 1
- where are php_errors written? HOT 2
- setting permission to properly handle file uploads
- Missing PDO HOT 4
- Not showing error 404
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docker-php-nginx.