Verdant TCS

Installing and Configuring New Relic for WordPress

10 min read

Third-Party Software Notice

Our support team cannot provide support for third-party software and services. However, if you spot an issue with this article please let us know and we will endeavor to bring it up-to-date ASAP.

Introduction

New Relic One is a powerful full-stack data analysis  platform for all your software’s metrics, events, and logs.

Their new pricing model makes their software a lot more accessible than it was previously and now even includes a free tier.

In parts 1, 2, and 3 we’ll walk through how to install New Relic on your vCanopy provisioned servers, and then we’ll look at how to finish up the configuration for Nginx and OpenLiteSpeed in their own respective sections (note that the PHP Agent installation on OpenLiteSpeed is done separately). After this there are additional sections on setting up your websites for monitoring in New Relic, and setting up additional logging if you’d like to do so.

Click on the images throughout the article to zoom in.

Please note that our support team is not available to answer questions around third-party software that is not a part of the vCanopy stack, however, if you think this article needs updating or can be improved, please let us know.

Also, special thanks to Sean Vandermolen for the information he contributed to the vCanopy Facebook community on installing New Relic on vCanopy. That information provided the foundation for this article.

Install Part 1. Get Your New Relic Install Command

If you don’t already have a New Relic account, you can sign up for one here: 

https://newrelic.com/

I’d recommend you choose the EU option when signing up.

Inside your New Relic account, click the “Add some data” button to get started:

GUIDED INSTALL

We’re going to use the Guided Install to monitor your Logs, PHP, MySQL, and Redis:

Select Linux:

And now click the “Begin installation” button:

INSTALLATION SCRIPT

New Relic will now create a 1 line command that you can copy and paste into your server. Before that though, we need to first complete Part 2 below.

Install Part 2. Server Preparation

Before running the New Relic install command you’ve just generated we first need to do some server prep so that both you and the server are ready for the installation process.

MYSQL ROOT PASSWORD

If you want New Relic to monitor MySQL, you’ll need to copy your MySQL root password BEFORE running the install commands, as it will ask you for this during the installation process. 

You can display your root password in the terminal with this command:

gp mysql -get-pass root

NGINX SERVER PHP PREPARATION 

Out of the box, the New Relic PHP installer isn’t able to identify the multiple PHP versions installed on the system. To solve for this we can symlink current to PHP directories with the paths that New Relic looks for by default.*

Run the following commands on your server:

mkdir /opt/php-7.1 /opt/php-7.1/bin /opt/php-7.2 /opt/php-7.2/bin /opt/php-7.3 /opt/php-7.3/bin /opt/php-7.4 /opt/php-7.4/bin
ln -s /usr/bin/php7.1 /opt/php-7.1/bin/php
ln -s /usr/bin/php7.2 /opt/php-7.2/bin/php
ln -s /usr/bin/php7.3 /opt/php-7.3/bin/php
ln -s /usr/bin/php7.4 /opt/php-7.4/bin/php

*Again, special thanks to Sean Vandermolen for contributing the above information. 

OPENLITESPEED SERVER PHP PREPARATION 

Just grab the MySQL password as detailed above.

No additional server preparation is necessary. We will install PHP separately after running the guided install.

Install Part 3. Install New Relic on Your Server

We’re now ready to run the installation script on your server.

Copy the command that was generated by following Install Part 1 above and hit Enter.

GUIDED INSTALL RUNDOWN

The script will first give you a rundown of the components to be installed (on OpenLiteSpeed the PHP Agent will be missing). Hit Enter to continue.

1. INSTALLING INFRASTRUCTURE AGENT

First up the Infrastructure Agent will run, and its completion ends with:
==> Installing Infrastructure Agent...success.

2. INSTALLING LOGS INTEGRATION

The Logs Integration will prompt you to confirm whether you want to tail these logs:

Hit Y and then Enter.

If your installation fails here with the following message:

“We encountered an issue during the installation: encountered an error while validating receipt of data for logs-integration: no validation was successful. most recent validation error: reached max validation attempts: no results returned.”

You should be able to solve this by running the following:

apt install td-agent-bit

Once installed, you can try the guided install again.

3. INSTALLING GOLDEN SIGNAL ALERTS

If you’d like New Relic to email you when the outlined alerts take place, hit Y and then Enter.

This will notify the email attached to your New Relic account.

4. INSTALLING MEMCACHED OPEN SOURCE INTEGRATION

During the Memcached install, just hit Enter.

5. INSTALLING MYSQL OPEN SOURCE INTEGRATION

The MySQL install will prompt you for the password that we ran the command for during the Install Part 2 section above.

Paste this and hit Enter. Entering passwords doesn’t give visual feedback on the command line, so it’s fine to hit Enter even though it doesn’t display.

6. INSTALLING PHP AGENT INSTALLER FOR DEBIAN

OpenLiteSpeed Note: In multiple tests while writing this article, the guided install does not attempt to install the PHP Agent on OLS. We’ll configure this separately in the OpenLiteSpeed section that follows.

The PHP installer will ask for a server name. Here you may want to enter your server name and then hit Enter. This will attempt to add your server name as the newrelic.appname inside the newrelic.ini files for each version of PHP. 

NOTE: Chances are it won’t change everything on Nginx so we’ll look at this in the following Nginx section.

The installer will then ask if you want to restart PHP. Hit y and then Enter.

Next, it will ask if you want to install the PHP Agent. Hit Y and then Enter.

7. INSTALLING REDIS OPEN SOURCE INTEGRATION

All of the defaults are correct for Redis. Hit Enter for each option to complete the installation process.

8. INSTALLATION COMPLETE!

Redis is the final component of the installation process. Once it’s complete you’ll see a summary:

Also, during the process, you’ll see each component being updated inside your New Relic account:

And once complete:

You can now click the “See your data” button to head to the server’s APM info.

Configure New Relic on Nginx

With New Relic installed, we now need to update/configure a few things to finish up.

1. “20-NEWRELIC.INI” REMOVAL

After the installation process is complete, if you run:
php -v
You may see a warning that reads: PHP Warning: Module ‘newrelic’ already loaded in Unknown on line 0. This same warning will also show up when restarting any version of PHP. This is due to the additional 20-newrelic.ini inside the /etc/php/7.*/fpm/conf.d. (* meaning 7.1, 7.2, 7.3, 7.4). Remove these with this command:
rm /etc/php/7.*/fpm/conf.d/20-newrelic.ini
And also the following to clear any that exist inside /etc/php/7.*/cli/conf.d:
rm /etc/php/7.*/cli/conf.d/20-newrelic.ini

2. UPDATE APPLICATION NAME AND LICENSE KEY INSIDE NEWRELIC.INI FILES

If you run the following command you’ll likely find that the New Relic install process didn’t set your server name and/or license in every newrelic.ini file:
grep -inr "newrelic.appname =" /etc
In my case, it only set this change inside /etc/php/7.3/mods-available/newrelic.ini as you can see in the output below:
root@18th-oct-steve-newrelic:~# grep -inr "newrelic.appname =" /etc
/etc/php/7.1/mods-available/newrelic.ini:112:newrelic.appname = "PHP Application"
/etc/php/7.1/cli/conf.d/newrelic.ini:112:newrelic.appname = "PHP Application"
/etc/php/7.1/fpm/conf.d/newrelic.ini:112:newrelic.appname = "PHP Application"
/etc/php/7.2/mods-available/newrelic.ini:112:newrelic.appname = "PHP Application"
/etc/php/7.2/cli/conf.d/newrelic.ini:112:newrelic.appname = "PHP Application"
/etc/php/7.2/fpm/conf.d/newrelic.ini:112:newrelic.appname = "PHP Application"
/etc/php/7.3/mods-available/newrelic.ini:112:newrelic.appname = "steve-server-ngx"
/etc/php/7.3/cli/conf.d/newrelic.ini:112:newrelic.appname = "PHP Application"
/etc/php/8.0/mods-available/newrelic.ini:112:newrelic.appname = "PHP Application"
/etc/php/7.4/mods-available/newrelic.ini:112:newrelic.appname = "PHP Application"
/etc/php/7.4/cli/conf.d/newrelic.ini:112:newrelic.appname = "PHP Application"
/etc/php/7.4/fpm/conf.d/newrelic.ini:112:newrelic.appname = "PHP Application"
Check the license with:
grep -inr "newrelic.license = " /etc
Unfortunately, because of the default name being “PHP Application” (two words frequently used with a space) and the missing license key, a mass search-replace isn’t easily done. You will need to edit each file individually to update them (or you could write your own bash script). Here I’m also missing 1 .ini file for 7.3. The contents of these files is all the same, so I’m going to use the file that has the correct name and license key and just copy it like this:
cd /etc/php/7.3/mods-available
cp newrelic.ini /etc/php/7.3/fpm/conf.d
Editing the Files
If you’re not using 7.1 or 7.2 on your sites, then simply leave these and only change the 7.3 and 7.3 files. Edit them each with nano, for example:
nano /etc/php/7.4/mods-available/newrelic.ini
The “newrelic.appname” is located on line 112. Scroll down, change the name, then save the file with CTRL+O, followed by Enter. Then exit the file with CTRL+X. Repeat for the remaining files.

3. CONFIGURE YOUR WEBSITES

You’re now ready to configure your WordPress websites. See the Configure Your Websites section for details, then once done, reboot your server.

Configure New Relic on OpenLiteSpeed

As noted above, during my tests with OpenLiteSpeed, the Guided Install does not attempt to install the PHP Agent on OLS servers. We’ll now configure this manually.

1. COPY YOUR LICENSE KEY

There will be multiple occasions where you will need your New Relic License Key below. Head over to your New Relic account, click your profile in the top right, and select “API Keys” from the dropdown. 

Here you’ll see 3 options. We need the License key in the middle – click the 3 dots on the right-hand side and then click Copy Key.

2. PHP AGENT SETUP

Run the following commands in order:

echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | sudo tee /etc/apt/sources.list.d/newrelic.list
wget -O- https://download.newrelic.com/548C16BF.gpg | sudo apt-key add -
sudo apt-get update

2. INSTALL THE PHP AGENT

Now we’re ready to run the installation. Run the following command:

sudo apt-get install newrelic-php5

The install will begin and then ask you to confirm you want to proceed. Type Y and hit Enter:

Paste your license key and hit Enter:

Give your server name a hit Enter:

The installation will complete shortly after.

3. CONFIGURE PHP MONITORING

For each version of PHP, we’re going to run through the same process. We’ll start with PHP 7.4.

Run the following two commands:

export NR_INSTALL_PATH=/usr/local/lsws/lsphp74/bin
newrelic-install

This will display the following options. Hit 1 and then Enter:

Now enter your license key and hit Enter:

You’ll now see 7.4 as an option. Hit 2 and then Enter to complete the installation for PHP 7.4.

Confirmation of successful installation will follow:

Now repeat the same steps for PHP 7.3 and 7.2 if you need them:

export NR_INSTALL_PATH=/usr/local/lsws/lsphp73/bin
newrelic-install
export NR_INSTALL_PATH=/usr/local/lsws/lsphp74/bin
newrelic-install

4. UPDATE THE APPLICATION NAME INSIDE NEWRELIC.INI FILES

If you run the following, you should find that New Relic inside of /etc/php is already using the name you entered in step 2 above:

grep -inr "newrelic.appname =" /etc

For example:

root@26th-oct-ols-newrelic3:~# grep -inr "newrelic.appname =" /etc
/etc/php/7.1/mods-available/newrelic.ini:112:newrelic.appname = "my-ols-server"
/etc/php/7.2/mods-available/newrelic.ini:112:newrelic.appname = "my-ols-server"
/etc/php/7.3/mods-available/newrelic.ini:112:newrelic.appname = "my-ols-server"
/etc/php/8.0/mods-available/newrelic.ini:112:newrelic.appname = "my-ols-server"
/etc/php/7.4/mods-available/newrelic.ini:112:newrelic.appname = "my-ols-server"

All good here.

However, in the newrelic.ini files that have just been created, they will still be called “PHP Application”:

grep -inr "newrelic.appname =" /usr/local/lsws/

The output will look as follows:

root@26th-oct-ols-newrelic3:~# grep -inr "newrelic.appname =" /usr/local/lsws/
/usr/local/lsws/lsphp72/etc/php/7.2/mods-available/newrelic.ini:112:newrelic.appname = "PHP Application"
/usr/local/lsws/lsphp74/etc/php/7.4/mods-available/newrelic.ini:112:newrelic.appname = "PHP Application"
/usr/local/lsws/lsphp73/etc/php/7.3/mods-available/newrelic.ini:112:newrelic.appname = "PHP Application"

To add your application name you’ll need to edit each file.

Edit them each with nano, for example:

nano /etc/php/7.4/mods-available/newrelic.ini

The “newrelic.appname” is located on line 112. Scroll down, change the name, then save the file with CTRL+O, followed by Enter. Then exit the file with CTRL+X.

Repeat for the remaining files.

5. RESTART OPENLITESPEED

We’re now set up. Next, run the following commands to finish up PHP service monitoring:

systemctl restart lsws
killall lsphp

6. CONFIGURE YOUR WEBSITES

You’re now ready to configure your WordPress websites. See the following section for details, then once done, reboot your server.

Configure Your  Websites

To monitor your websites as their own individual apps you can give them their own appname inside their individual .user.ini files.

You can edit a websites .user.ini file with the following command (replacing site.url with your domain name):

nano /var/www/site.url/htdocs/.user.ini

At the bottom of the file add the following and customize it for your website:

newrelic.appname = "{sitename}"

OR

newrelic.appname = "{sitename};{servername}"

For example:

newrelic.appname = "steve.com"
newrelic.appname = "steve.com;steve-server-ngx"

This pumps site-specific data to an app called “steve.com” inside New Relic, and if you also use the server-wide app name it will collect data for all your websites.

Save the file with CTRL+X followed by Enter. Exit nano with CTRL+X.

Repeat for your other websites.

10up Plugin

10up also have a free WordPress plugin that could potentially make this part easier for you. You can learn more about it here:

New Relic Reporting for WordPress

REBOOT YOUR SERVER

Now everything has been configured, you just need to reboot your server. Before this, you could also follow the section below to add additional logs if you wish to do, then reboot after that. 

Reboot your server with following command:

sudo reboot

New Relic is now setup on your server.

Add Additional Logs (Optional)

You may also want to push additional logs to New Relic as well. 

To do this edit the logging.yml file with:

nano /etc/newrelic-infra/logging.d/logging.yml

Below is an example of how this might look if you add some additional logs (don’t forget to replace site.url with your domain if using as a template):

logs:
- name: alternatives.log
  file: /var/log/alternatives.log
- name: cloud-init.log
  file: /var/log/cloud-init.log
- name: auth.log
  file: /var/log/auth.log
- name: dpkg.log
  file: /var/log/dpkg.log
- name: newrelic-cli.log
  file: /root/.newrelic/newrelic-cli.log
  attributes:
    newrelic-cli: true

- name: mysql.error.log
  file: /var/log/mysql/error.log
  attributes:
    logtype: mysql-error

- name: site.url.access.log
  file: /var/log/nginx/site.url.access.log
  attributes:
    logtype: nginx

- name: site.url.error.log
  file: /var/log/nginx/site.url.error.log
  attributes:
    logtype: nginx-error
vCanopy Logs

You can view all of your available logs in this article, including their file paths:

vCanopy Logs – How to Find Them and When to Use Them

New Relic Documentation

For more info on logging and New Relic, check out there documentation here:

https://docs.newrelic.com/docs/logs/forward-logs/forward-your-logs-using-infrastructure-agent/

https://docs.newrelic.com/docs/logs/log-management/ui-data/parsing/

Uninstall New Relic

New Relic is likely something you’ll want to stick with. It’s a serious tool for serious workloads.

If you do want to remove it though, the following are the commands to remove the Infrastructure Agent and PHP Agent.

1. UNINSTALL THE INFRASTRUCTURE AGENT

Run the following command:

sudo apt-get remove newrelic-infra

More information can be found here:

https://docs.newrelic.com/docs/infrastructure/install-infrastructure-agent/update-or-uninstall/uninstall-infrastructure-agent/

2. UNINSTALL THE PHP AGENT

Run the following command:

apt-get remove newrelic-php5

And attempt to clean up any remaining configuration files with:

newrelic-install purge

And/or:

apt-get remove --purge newrelic

More details can be found here:

https://docs.newrelic.com/docs/apm/agents/php-agent/advanced-installation/uninstalling-php-agent/

Search the Knowledge Base

New to vCanopy?

Get started with our FREE Core plan today! We bring the software, you bring the hardware.