Articles

How to Install New Relic for Monitoring PHP Apps

In this tutorial, we'll show you how to install and configure New Relic for monitoring PHP apps. You need to follow this tutorial rather than the standard New Relic instructions because ServerPilot installs its own builds of PHP on your servers.

This article is only for New Relic's PHP app monitoring. For New Relic's server monitoring, you should follow the standard instructions provided by New Relic.

Please be aware that New Relic's per-process memory reporting is very inaccurate.

Install the New Relic PHP Package

SSH in to your server as root and run the following commands:

wget -O - https://download.newrelic.com/548C16BF.gpg | sudo apt-key add -

sudo bash -c "echo deb http://apt.newrelic.com/debian/ newrelic non-free > /etc/apt/sources.list.d/newrelic.list"

sudo apt-get update

sudo apt-get install newrelic-php5

Add New Relic to a Specific PHP Version

If you want New Relic available for PHP 5.4, 5.5, 5.6, and 7.0, repeat the following instructions for each version.

First, start the New Relic installer by running the following commands as root. IMPORTANT: Replace X.Y in all commands below with either 7.0, 5.6, 5.5, or 5.4.

sudo NR_INSTALL_PATH=/opt/sp/phpX.Y/bin newrelic-install

In the installer, choose #1 ("Install the New Relic Agent and Daemon").

Enter your New Relic license key when prompted.

If you are prompted to select a directory in which to install New Relic, select the option that matches the PHP version you are adding New Relic to.

The New Relic installer will create the file /etc/phpX.Y-sp/conf.d/newrelic.ini. This is where you can edit your New Relic license key, if required.

Finally, restart PHP with this command:

sudo service phpX.Y-fpm-sp restart

That's it. You can confirm that New Relic installed by looking for it in the output of phpinfo() or with phpX.Y-sp -i at the command line. For example:

$ php5.4-sp -i | grep newrelic
newrelic
newrelic.daemon.logfile => /var/log/newrelic/newrelic-daemon.log
newrelic.daemon.ssl => enabled
newrelic.logfile => /var/log/newrelic/php_agent.log
newrelic.loglevel => no value
...

Set the New Relic App Name

You can identify individual apps to New Relic by creating a .user.ini file in each app's web root directory (that is, create the file apps/APPNAME/public/.user.ini) with the contents:

newrelic.appname = "APPNAME"

This sets the name of the New Relic application that metrics will be reported into. This is how the name will be seen on the New Relic website.


Last updated: September 27, 2016