NewRelic Setup for Ubuntu Server with PHP, FPM, Nginx and MySQL

This guide is for newrelic service.

Add Ubuntu Repo

Run following commands once on target server which need to be monitored:

wget -O - | sudo apt-key add -
sudo sh -c 'echo "deb newrelic non-free" > /etc/apt/sources.list.d/newrelic.list'
apt-get update

Server Monitoring

To enable server monitoring, install package newrelic-sysmond

apt-get install newrelic-sysmond

Then add license key:

nrsysmond-config --set license_key=XXXXXXXXXX

You can get your license key, i.e. value of XXXXXXXXXX from

Start monitoring daemon:

service newrelic-sysmond start

This will start monitoring CPU, Memory, Disk utilization.

PHP App Monitoring

Since we are running WordPress (mostly), we need to setup PHP app monitoring as well.

For this there is a separate package in newrelic repo. Run following command to install it:

sudo apt-get install newrelic-php5

Next run command:

newrelic-install install

Above will prompt you for license key, which is same as previous step.

You may manually need to copy newrelic ini file from php-cli to php-fpm:

cp /etc/php5/cli/conf.d/newrelic.ini /etc/php5/fpm/conf.d/

If you are monitoring multiple servers with  newrelic.appname, you may like to change newrelic.appname in  /etc/php5/fpm/conf.d/newrelic.ini to something unique.

You may need to restart PHP monitor:

service php5-fpm restart

PHP app monitor will graph PHP response time, error rate and throughput.

PHP-FPM and Nginx Status Monitoring

Before we proceed, I am assuming that you already have PHP-FPM status and Nginx status page enabled.

For PHP-FPM and Nginx, we will be using a third party plugin coded in python. (Github Link)


pip install newrelic-plugin-agent


Copy sample config file and open it in editor.

cp /opt/newrelic_plugin_agent/newrelic_plugin_agent.cfg  /etc/newrelic/newrelic_plugin_agent.cfg
vim /etc/newrelic/newrelic_plugin_agent.cfg

Fine license_key line and change it’s value to your newrelic license key.

Alter fpm config-block to look like below:

      name: UNIQUNE-NAME
      path: /status
      query: json

Alter nginx config-block to look like below:

     name: UNIQUE-NAME
     path: /nginx_status


newrelic_plugin_agent -c /etc/newrelic/newrelic_plugin_agent.cfg -f

If all looks good, start monitoring using:

newrelic_plugin_agent -c /etc/newrelic/newrelic_plugin_agent.cfg

We just removed -f from end.

MySQL Monitoring

You can get latest download link for MySQL plugin from

wget -O nr-mysql.tar.gz 
tar xvf nr-mysql.tar.gz 
cd newrelic_mysql_plugin-1.0.9
cp config/ config/
cp config/template_mysql.instance.json config/mysql.instance.json
cp config/ config/

Then open  config/ and update  licenseKey.

Also update mysql username and password in  config/mysql.instance.json

Finally start mysql monitoring:

java -jar newrelic_mysql_plugin-1.0.9.jar

If you don’t have java installed, you may need to install it first.