Php: New Relic

Created on 27 Jan 2016  路  10Comments  路  Source: docker-library/php

Hi Guys,

Sorry that this isn't really an issue, but rather a question.

How do you monitor your PHP application with New Relic in a docker container? Do you have a separate container and link it to all your PHP containers?

Or do you apt-get install it and set the configuration for it?

Cheers,

Most helpful comment

I haven't checked if it will work with PHP7. That'd be a question for NewRelic on whether or not they support 7 yet.

Here is our full mostly un-changed dockerfile. While it targets PHP 5.4 we use very similar iterations of this in other PHP 5.6 and lower configurations:

FROM php:5.4-apache
MAINTAINER Peter Olds <[email protected]>

# Install php-zip package
RUN apt-get update \
    && apt-get install -y zlib1g-dev \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install zip

# Install php-GD library
RUN apt-get update \
    && apt-get install -y libpng-dev \
    && docker-php-ext-install gd

# Install php-exif library
RUN apt-get update \
    && docker-php-ext-install exif

# Install php-redis
ADD php-redis /opt/php-redis
RUN apt-get update \
    && cd /opt/php-redis \ 
    && echo `pwd` \
    && /usr/local/bin/phpize \
    && ./configure \
    && make && make install 

# Install mbstring
RUN docker-php-ext-install mbstring

# Install php-MySQL
RUN docker-php-ext-install mysql

# Enable mod_rewrite
RUN cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/

# Install New Relic
RUN apt-get update 
RUN apt-get -yqq install wget
RUN apt-get -yqq install python-setuptools
RUN easy_install pip
RUN mkdir -p /opt/newrelic
WORKDIR /opt/newrelic
RUN wget -r -nd --no-parent -Alinux.tar.gz \
    http://download.newrelic.com/php_agent/release/ >/dev/null 2>&1 \
    && tar -xzf newrelic-php*.tar.gz --strip=1
ENV NR_INSTALL_SILENT true
ENV NR_INSTALL_KEY {{key "NEWRELIC_LICENSE_KEY"}}
RUN bash newrelic-install install
WORKDIR /
RUN pip install newrelic-plugin-agent
RUN mkdir -p /var/log/newrelic
RUN mkdir -p /var/run/newrelic

ADD config /usr/local/etc/php/conf.d/
ADD src/html /var/www/html
ADD src/app /var/www/app

RUN ["chown", "-R", "www-data:www-data", "/var/www/html"]
CMD ["apache2", "-DFOREGROUND"]

All 10 comments

We build it into the container:

# Install New Relic
RUN apt-get update 
RUN apt-get -yqq install wget
RUN apt-get -yqq install python-setuptools
RUN easy_install pip
RUN mkdir -p /opt/newrelic
WORKDIR /opt/newrelic
RUN wget -r -nd --no-parent -Alinux.tar.gz \
    http://download.newrelic.com/php_agent/release/ >/dev/null 2>&1 \
    && tar -xzf newrelic-php*.tar.gz --strip=1
ENV NR_INSTALL_SILENT true
ENV NR_INSTALL_KEY NEWRELIC_LICENSE_KEY_HERE
RUN bash newrelic-install install
WORKDIR /
RUN pip install newrelic-plugin-agent
RUN mkdir -p /var/log/newrelic
RUN mkdir -p /var/run/newrelic

Awesome thank you for the info, I will give it a try.

The only change I made it to copy the license in, thank you so much!

# Install New Relic
RUN apt-get update 
RUN apt-get -yqq install wget
RUN apt-get -yqq install python-setuptools
RUN easy_install pip
RUN mkdir -p /opt/newrelic
WORKDIR /opt/newrelic
RUN wget -r -nd --no-parent -Alinux.tar.gz \
    http://download.newrelic.com/php_agent/release/ >/dev/null 2>&1 \
    && tar -xzf newrelic-php*.tar.gz --strip=1
COPY config/newrelic.license /opt/newrelic/
ENV NR_INSTALL_SILENT true
RUN export NR_INSTALL_KEY=`cat /opt/newrelic/newrelic.license` 
RUN bash newrelic-install install
WORKDIR /
RUN pip install newrelic-plugin-agent
RUN mkdir -p /var/log/newrelic
RUN mkdir -p /var/run/newrelic

What base image are you using?

I'm trying to do this with php:5.6.18-fpm and I'm having this error: ALERT: oops, unknown child (6) exited with code 0. Please open a bug report (https://bugs.php.net).

We use several different versions of php+apache

Mine doesn't seem to be working just yet. Do you mind sharing your Dockerfile to show us how you implemented this? Then again I am using PHP7 with this. Do you think that would be an issue?

I haven't checked if it will work with PHP7. That'd be a question for NewRelic on whether or not they support 7 yet.

Here is our full mostly un-changed dockerfile. While it targets PHP 5.4 we use very similar iterations of this in other PHP 5.6 and lower configurations:

FROM php:5.4-apache
MAINTAINER Peter Olds <[email protected]>

# Install php-zip package
RUN apt-get update \
    && apt-get install -y zlib1g-dev \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install zip

# Install php-GD library
RUN apt-get update \
    && apt-get install -y libpng-dev \
    && docker-php-ext-install gd

# Install php-exif library
RUN apt-get update \
    && docker-php-ext-install exif

# Install php-redis
ADD php-redis /opt/php-redis
RUN apt-get update \
    && cd /opt/php-redis \ 
    && echo `pwd` \
    && /usr/local/bin/phpize \
    && ./configure \
    && make && make install 

# Install mbstring
RUN docker-php-ext-install mbstring

# Install php-MySQL
RUN docker-php-ext-install mysql

# Enable mod_rewrite
RUN cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/

# Install New Relic
RUN apt-get update 
RUN apt-get -yqq install wget
RUN apt-get -yqq install python-setuptools
RUN easy_install pip
RUN mkdir -p /opt/newrelic
WORKDIR /opt/newrelic
RUN wget -r -nd --no-parent -Alinux.tar.gz \
    http://download.newrelic.com/php_agent/release/ >/dev/null 2>&1 \
    && tar -xzf newrelic-php*.tar.gz --strip=1
ENV NR_INSTALL_SILENT true
ENV NR_INSTALL_KEY {{key "NEWRELIC_LICENSE_KEY"}}
RUN bash newrelic-install install
WORKDIR /
RUN pip install newrelic-plugin-agent
RUN mkdir -p /var/log/newrelic
RUN mkdir -p /var/run/newrelic

ADD config /usr/local/etc/php/conf.d/
ADD src/html /var/www/html
ADD src/app /var/www/app

RUN ["chown", "-R", "www-data:www-data", "/var/www/html"]
CMD ["apache2", "-DFOREGROUND"]

Thank you so much for sharing! I will have to fiddle when I have some spare time

My issue was with the newrelic.ini file. I overrides any previous global .ini directive, so my .ini license key was overridden by an empty string.

Closing, given that this isn't an issue specific to the PHP image. I recommend contacting New Relic for help with their solutions, if necessary. :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ihorsamusenko picture ihorsamusenko  路  4Comments

nojimage picture nojimage  路  3Comments

solocommand picture solocommand  路  3Comments

pavlakis picture pavlakis  路  3Comments

2Kable picture 2Kable  路  3Comments