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"]
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);
The newrelic.ini file was removed because it generates the following run-time error:
Therefore, the setting of the variables to the php.ini file is carried out, which loads the default options of newrelic.
Top comments (5)
Hey David,
This is an interesting approach. I have been trying to get an official support idea from NewRelic.
Unfortunately I am erroring here:
executor failed running [/bin/sh -c source .export && echo $' \n extension = "newrelic.so" \n newrelic.logfile = "/dev/null" \n newrelic.loglevel = "error" \n newrelic.appname = "NicT
est" \n newrelic.license = "MY_LICENSE"' >> /usr/local/etc/php/php.ini]: exit code: 2
Could the path no longer be valid since you cooked this up?
Thanks
Nic
Just to add to this. I believe I am missing your .export file in your working directory. Do you know the contents of it?
Hey Nic, thanks for your advice
I generate my .export file from a pipeline to set my app_name and app_licence, I removed this section for the example.
If you want to use the .export file, you need to create this in the project folder with a structure like this, and then export these variables to handle in the process
Hey David, thank you for your guide!
I've tried to follow it but when deploying it I just get "Deployment Failed" without any specific error from vapor command.
Is it possible that with newer versions of vapor or laravel there is some difference to do in the installation process?
We were able to deploy without failure but still no data is pushed to New Relic