New Relic is a server and application monitoring tool which can be used to track resource usage on servers and monitor application logs. In this article, we will show you exactly how to use New Relic to monitor errors on your RunCloud servers using Nginx and Apache2 stack.

So – without further ado – let’s dive right in.

1. Sign Up For a New Relic Account

new relic homepage

Before we can install New Relic on your server, you’ll need to create a New Relic account here. Don’t worry about any paid plans – the free plan is perfectly sufficient for the purposes of this tutorial.

2. Add New Relic’s Agent

Start by logging in to your dashboard and look for the “Add Data” option in the left menu. Once you’ve opened it, select the “Guided Install” option to automatically install the agent and all necessary plugins.

Note: This method does not work for servers running on OpenLiteSpeed. Skip to the next section to see the appropriate steps for this.

Next, make sure that you are on the “Auto-discovery” tab, and select the Linux option.

Review the displayed information, and click “Begin installation” when ready. This will display a shell command that will install New Relic on your server. Don’t close this window yet.

3. Log In To Your Server

You’ll need to connect to your server via SSH to install the New Relic agent. Make sure that you have Super User privileges to run the installation script.

You can use the following command to connect via the root user. Make sure to add the IP address of your server and the location of your SSH key before running the command.

ssh root@<ip address> -i <private key>

4. Run The New Relic Installation Script

Once you have logged in to the server, paste and run the command displayed on the New Relic dashboard. This will start the installation script.

At this stage, click ‘Enter’ to perform the guided install that will automatically discover and recommend the integrations appropriate for your web applications. This will also add the infrastructure agent which is extremely useful for performance monitoring.

Once the infrastructure agent is installed, you’ll be asked if you want to monitor PHP applications. Press ‘Y’ to continue the installation, or ‘N’ to cancel it.

You’ll then be prompted to enter some basic information – such as the name of your application. Fill these fields in as necessary.

You’ll also need to specify whether the agent should restart the NGINX server automatically or not. If you have a production server running on this machine, we recommend restarting the services manually to avoid abrupt interruptions.

Wait for the installation to complete. After completion you might get a message that the installation of PHP Agent was incomplete. Wait for a few minutes, and refresh your New Relic dashboard. If the data logged by your PHP application is not displayed in the New Relic dashboard, you can follow the steps laid out in the next section of this tutorial.

Installing New Relic for a Specific PHP Application

Since RunCloud uses its own PHP releases that are not present in the default directory, you’ll need to set the New Relic installation path to match RunCloud’s PHP path. This can be done by running the following command:

# For Apache2 servers
NR_INSTALL_PATH=/RunCloud/Packages/php*rc/bin
# For OpenLiteSpeed servers
NR_INSTALL_PATH=/usr/local/lsws/lsphp*/bin

The above command will look for all the PHP versions installed on your server. It will then add their path to the NR_INSTALL_PATH environment variable before running the New Relic installation. Run the following command to start the installation:

export NR_INSTALL_PATH
newrelic-install

Press ‘1’ to install, and then press ‘Enter’. You’ll be asked for the New Relic License key, which you can find in the New Relic dashboard. Click on your username in the bottom left of the screen, and select the ‘API keys’ option to open the menu. 

Here, you can either create a new key, or use an existing key. Select the key with type of “INGEST – LICENSE”, click on the options button, and select “copy key”.

Navigate back to your terminal and paste this key into the input field to continue the installation process.

You will then be prompted to select the PHP version, and enter ‘all’ to install New Relic in all of the directories.

Once you have completed the installation you’ll get a list of all the PHP directories being monitored – along with their installation status.

At the time of writing New Relic supports PHP up to version 8.1. In the following example we are using PHP 8.2, which is not supported. New Relic will ignore this particular instance of PHP and continue monitoring other applications.

Once you have installed the agent, you can customize its name to identify it. Use the following command to finish the installation and locate the New Relic configuration files:

NR_INSTALL_SILENT=1 newrelic-install install
find / -name newrelic.ini

In each configuration file you can customize the settings as you see fit. We will change the name of the application to something descriptive for easier understanding. To do this, run the following command to locate the .appname setting in the configuration file, (make sure to change the path of the file accordingly):

cat -n /etc/php81rc/conf.d/newrelic.ini | grep .appname

In the above example we can see that the .appname setting is present on line number 112 in the /etc/php81rc/conf.d/newrelic.ini file. You can use your preferred text editor to open this file and change the name to something descriptive.

If you want to verify if you are using the correct license key, you can do so with the following command (make sure to update the path of the file):

cat -n /usr/local/lsws/lsphp74/etc/php/7.4/mods-available/newrelic.ini | grep "newrelic.license"

If you see “REPLACE_WITH_REAL_KEY” after running the above command, then you can just open the file in a text editor and replace it manually.

To be certain that all of the latest changes have been applied and have taken effect you can run the following command:

# For Apache2 servers
systemctl reload php*rc-fpm
# For OpenLiteSpeed servers
systemctl restart lsws-rc
killall lsphp

Reviewing New Relic Dashboard

And that’s it – you’re all set! Your New Relic account will now be collecting data and monitoring your server. You should be able to see your server metrics, along with any additional monitors that you have installed in the New Relic dashboard.

If you have a general purpose web application then you can track its metrics in the “APM & Services” section. There you can see error rates, logs and set alerts to notify you in case of a failure.

If you are running a website then you can take advantage of “Browser” monitoring functionality, which tracks your website’s Core Web Vitals.

And then, once you’ve successfully logged in – run the installation command provided in New Relic’s dashboard which will look something like this:

After Action Report

Using a server monitoring platform such as New Relic will allow you to quickly identify and resolve issues that affect your website’s performance. You can set up real-time monitoring and alerts to proactively assess potential problems that can cause downtime.

Integrating New Relic with RunCloud can provide you with invaluable insights into your server’s performance and help you optimize it for better speed and reliability. By following the above steps you can easily set up New Relic to monitor your server’s metrics, including CPU usage, memory consumption, and network traffic.

Not a fan of managing your own servers?

This is exactly why we built RunCloud.

Painless server configuration that automates all of this so you don’t need to spend hours figuring it out – get started with RunCloud today & get up and running in minutes.

Have any other questions, or already using New Relic to monitor your web applications? Let us know & join the conversation by leaving a comment below. 💬