Install New Relic on your PHP Application Docker image
10 MAY 2018
7 mins read
Why writing this?
New Relic is a great tool for monitoring your app’s performance. It also can be tricky to install, and the php script
provided in the manual installation documentation does not work very well. Here’s how I installed quite
Know your PHP
Let’s implement it on the dockerized project of this previous article.
This means we will use the same directory structure. If you don’t feel like reading it, at least look at the Dockerfile.
First, you will need information about the php installation of the platform your app will be running. In this case, will
be the container of the docker image. Build it and access the container by running
Now, let’s get the information we need:
The value you need should be a number like 20160303
This should get you x86 or x64
You’ll need the directory. For example: /usr/lib/php/20160303
See if it’s enabled or disabled:
Updating your Dockerfile
We’ll implement this in a Dockerfile, but you can always run manually the commands. This is up to your implementation.
First, we’ll write our New Relic’s configuration file, so it’s easy to modify.
Put it in build/newrelic.ini.
It is true that New Relic identifies your application by the newrelic.appname configuration. If you hard code your
configuration in the build/newrelic.ini file, then if you run multiple instances of it, you won’t be able to know
which application is which. If you are ok with this, feel free to hard code it. If not, keep reading.
In our newrelic.ini file, we have the default name New Relic provides. We will leave it like this and change it according
to an environment variable that lives inside the docker container, so you can change it depending on which environment
you deploy. You will have, for example, this names on New Relic applications list:
Currently, our Dockerfile runs this at the bottom:
In the Dockerfile we don’t have access to the container’s environment variables, but we can create an entrypoint.sh
file that our Dockerfile can run, where we do have access to them. Put it in your build folder.
In your Dockerfile, copy the build/entrypoint.sh file to the root directory and add execution permissions:
Now you can edit your Dockerfile, remove the CMD ["supervisord", "-n"] line and add the following:
This should allow you to deploy different instances of your application and New Relic will be able to differentiate them