Integrate Newrelic in Laravel Vapor

davidv99

David Valbuena

Posted on May 7, 2021

Integrate Newrelic in Laravel Vapor

Using docker-based deployments we can configure newrelic from the same file {env} .dockerfile, here we must install and set the newrelic variables, we must also create an entrypoint.sh file in which we will indicate the image the start of the processes to be carried out:

{env}.dockerfile

FROM laravelphp/vapor:php74

# Download and install newrelic: https://download.newrelic.com/php_agent/release/
RUN \
    curl -L "https://download.newrelic.com/php_agent/release/newrelic-php5-9.16.0.295-linux-musl.tar.gz" | tar -C /tmp -zx && \
    export NR_INSTALL_USE_CP_NOT_LN=1 && \
    export NR_INSTALL_SILENT=1 && \
    /tmp/newrelic-php5-*/newrelic-install install

# add global var to php.ini file
RUN \
    echo $' \n\
    extension = "newrelic.so" \n\
    newrelic.logfile = "/dev/null" \n\
    newrelic.loglevel = "error" \n\
    newrelic.appname = "REPLACE_APP_NAME" \n\ 
    newrelic.license = "REPLACE_NEWRELIC_LICENCE"' >> /usr/local/etc/php/php.ini

# Remove newrelic.ini file
RUN rm /usr/local/etc/php/conf.d/newrelic.ini

RUN mkdir -p /usr/local/etc/newrelic && \
  echo "loglevel=error" > /usr/local/etc/newrelic/newrelic.cfg && \
  echo "logfile=/dev/null" >> /usr/local/etc/newrelic/newrelic.cfg

COPY . /var/task

USER root
RUN chmod +x /var/task/entrypoint.sh
ENTRYPOINT ["/var/task/entrypoint.sh"]
Enter fullscreen mode Exit fullscreen mode

The entrypoint.sh file is necessary to start the execution of PHP and indicate the type of process that will be carried out with newrelic

#! /bin/sh

#start Newrelic daemon
newrelic-daemon -c /usr/local/etc/newrelic/newrelic.cfg

#start PHP
/opt/bootstrap

newrelic_background_job(false);
Enter fullscreen mode Exit fullscreen mode

The newrelic.ini file was removed because it generates the following run-time error:
newrelic error

Therefore, the setting of the variables to the php.ini file is carried out, which loads the default options of newrelic.

💖 💪 🙅 🚩
davidv99
David Valbuena

Posted on May 7, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related