mlocati / docker-php-extension-installer

Easily install PHP extensions in Docker containers
MIT License
4.18k stars 378 forks source link

Support to install newrelic #904

Closed leroy0211 closed 4 months ago

leroy0211 commented 5 months ago

Hi,

We use newrelic a lot in our projects, and I'm wondering if this is a great candidate to install with install-php-extensions.

This might be related to #784 , but it was closed with status completed.

mlocati commented 5 months ago

I don't know newrelic... is it a PHP extension? How do you install it?

leroy0211 commented 4 months ago

newrelic is a APM monitoring tool, which uses a newrelic.ini file for configuration, located in $PHP_INI_DIR.

There are basically 2 ways of using the newrelic php daemon. Either as separate container, or in the same container as php is running. Both need the newrelic php agent installed in the image that is running php.

docs: https://docs.newrelic.com/docs/apm/agents/php-agent/advanced-installation/docker-other-container-environments-install-php-agent

The newrelic agent adds a few "native" php functions to interact with newrelic. see: https://docs.newrelic.com/docs/apm/agents/php-agent/php-agent-api/guide-using-php-agent-api/

We usually install newrelic in our images like so:

RUN cd ~ \
    && export NEWRELIC_VERSION="$(curl -sS https://download.newrelic.com/php_agent/release/ | sed -n 's/.*>\(.*linux\).tar.gz<.*/\1/p')" \
    && 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 \
    && NR_SO_FILE=`readlink /usr/local/lib/php/extensions/no-debug-non-zts-*/newrelic.so` \
    && mv "${NR_SO_FILE}" /usr/local/lib/php/extensions/no-debug-non-zts-*/newrelic.so \
    && chown -R www-data:www-data /var/log/newrelic \
    && cd .. \
    && unset NEWRELIC_VERSION \
    && rm -rf "${NEWRELIC_VERSION}"

A few notes, this doesn't change the newrelic.ini file located in $PHP_INI_DIR, so neither a license key or application name is configured (which are the minimum requirements for this extension to work).

We often mount a separate newrelic.ini in our containers, which override the default newrelic.ini

What do you think? Would this be a php extension to add to docker-php-extension-installer?

mlocati commented 4 months ago

Thanks for the detailed instructions! Done.

ro0NL commented 4 months ago

thank you, it works :shipit: