Your data. Anywhere you go.

New Relic for iOS or Android

Download on the App Store    Android App on Google play

New Relic Insights App for iOS

Download on the App Store

Learn more

Close icon

Relic Solution: cPanel and the New Relic PHP Agent



Note: in version of the PHP Agent, a new option for changing the daemon socket was added: newrelic.daemon.address. This document references newrelic.daemon.port, but if you are on a release >= v9.2.0.247, we recommend using newrelic.daemon.address instead.

Why is cPanel different?

cPanel manages all of the server config files including PHP. This can make things confusing if you try to make manual edits to files that are generated by cPanel like the php.ini. This attempts to clarify how cPanel configures PHP and provide some steps to install the agent successfully on cPanel systems.

By default cPanel installs 3 different versions of PHP and numerous handler options for each including DSO (mod_php) and PHP-FPM and can install every supported version of PHP and even more handler options with a few clicks in WHM. Each cPanel user account on the server can be assigned a different PHP version and handler.

Easy Apache

The biggest impact to New Relic is cPanel’s Easy Apache. In the past this would completely recompile Apache, PHP, and any selected modules from source each time it ran. This would blow away anything installed outside of Easy Apache including New Relic unless it was included in the template files for Easy Apache. Thankfully, this is no longer the case with Easy Apache 4 which now uses cPanel issued RPMs to install various components. This is much less likely to blow away New Relic installs but similar steps should be followed as with installing other PHP extensions not included in Easy Apache. You may need to use Easy Apache to modify Apache with DSO to a supported configuration

There is currently no out-of-the-box option to install the New Relic PHP Agent via Easy Apache. Below is an example of the many options you get with installing PHP using Easy Apache:

Installing the New Relic Agent

Running the installer will only install the agent for the default PHP install. This can be viewed or modified in WHM:

This setting controls the version of PHP of the /usr/bin/php. Other versions of PHP installed by Easy Apache will be in directories like /opt/cpanel/ea-php56/root/usr/bin/

To install the agent for all versions of PHP on a cPanel system you can add the NR_INSTALL_PATH environment variable before running the installer:

[root@dolores]# export NR_INSTALL_PATH=/opt/cpanel/ea-php*/root/usr/bin/
[root@dolores]# newrelic-install
New Relic PHP Agent Installation (interactive mode)
Enter New Relic license key (or leave blank):
Below is a list of the directories in which we found a copy of PHP.
Please select the directory or directories for which you wish to install
New Relic. You can select either a single directory or
multiple directories by separating each choice with either a space or a
comma. To select all of the directories shown, please enter the special
keyword 'all' (without the quotes).
1) /bin
2) /usr/bin
3) /usr/local/bin
4) /opt/cpanel/ea-php56/root/usr/bin/
5) /opt/cpanel/ea-php70/root/usr/bin/
6) /opt/cpanel/ea-php71/root/usr/bin/
7) /opt/cpanel/ea-php72/root/usr/bin/
0) Exit
Selection (1-7, 0 to exit or all):

Because cPanel systems are most often are on CentOS you will likely also need to use the abstract socket to get around selinux settings. The following command will update all of your PHP installs to use the same abstract socket:

sed -i -e "s/;newrelic.daemon.port =.*/newrelic.daemon.port = "@newrelic-daemon"/" /opt/cpanel/ea-php*/root/etc/php.d/newrelic.ini

Likewise, you can set the default appname for all PHP installs with the following:

sed -i -e ` `"s/newrelic.appname =.*/newrelic.appname = "` `Cpanel App` `"/"`   `/opt/cpanel/ea-php*/root/etc/php.d/newrelic.ini

Afterwards, you’ll need to restart services to pick up the changes. Do this via WHM. Apache and FPM should both be restarted as different sites might be using one or the other for PHP:

Per-directory PHP settings

Because cPanel is often used in shared hosting environments you will likely want to set different sites to use different appnames. To prevent your settings from being overwritten by cPanel you should use the MultiPHP INI Editior in your cPanel account (not WHM unless you want system wide settings). This should allow you to modify and set per-directory PHP values in a way that your selected PHP handler supports ie .htaccess for DSO and .user.ini for PHP-FPM. Basic mode won’t contain New Relic settings so you’ll need to use the Editor Mode to add “newrelic.appname”

Installing New Relic PHP Agent on managed server without root access
Newrelic-daemon stopped running
Installing agent on cpanel