[EA3] New Relic APM on cPanel & CloudLinux CageFS

Many System Administrators tried to get PHP apps hosted on a cPanel server with CloudLinux and CageFS enabled to report to New Relic APM.  We presume that most of them failed since we struggled finding a proper yet complete HowTo.

Sure thing that the easiest way would simply be to get onboard with our fully managed hosting service or hire us in order to install it for your company.

For those who would like to proceed with their own staff, please follow this simple HowTo:

To get around this, we did the following:

  1. Login via ssh as root

  2. Install New Relic System Monitor and PHP RPM using the official documentation
    (from the official doc)
    1. Adding the repo
      rpm -Uvh https://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm

    2. Install the packages
      yum install newrelic-sysmond newrelic-php5 -y

    3. Add your New Relic key
      nrsysmond-config --set license_key=YOUR_LICENSE_KEY

    4. Start the System Monitoring daemon
      /etc/init.d/newrelic-sysmond start

    5. Let's run the auto-installer for PHP newrelic-install  (choose /usr/local/bin when asked)

  3. Install PHP module in Alternate PHP
    1. Download the latest modules from the official website (https://download.newrelic.com/php_agent/release/)
      cd ~ && wget https://download.newrelic.com/php_agent/release/newrelic-php5-

    2. Uncompress the archive
      tar zxvf newrelic-php5-

    3. Copy the module to the proper directories
      cp ~/newrelic-php5- /opt/alt/php54/usr/lib64/php/modules/newrelic.so
      cp ~/newrelic-php5- /opt/alt/php55/usr/lib64/php/modules/newrelic.so
      cp ~/newrelic-php5- /opt/alt/php56/usr/lib64/php/modules/newrelic.so
      cp ~/newrelic-php5- /opt/alt/php70/usr/lib64/php/modules/newrelic.so
      cp ~/newrelic-php5- /opt/alt/php71/usr/lib64/php/modules/newrelic.so

  4. Find out NewRelic group ID
    id -g newrelic

  5. Edit the /etc/sysctl.conf file, and add the following lines (replace GroupID with NewRelic group ID found in the previous point)
    fs.proc_can_see_other_uid = 0
    fs.proc_super_gid = GroupID
  6. Reload the configuration
    sysctl -p

  7. Append the user "newrelic" to the file /etc/cagefs/exclude/systemuserlist
    echo "newrelic" >> /etc/cagefs/exclude/systemuserlist

  8. Move /etc/newrelic/newrelic.cfg.template to /etc/newrelic/newrelic.cfg
    mv /etc/newrelic/newrelic.cfg.template /etc/newrelic/newrelic.cfg

  9. Add/Modify the following lines in /etc/newrelic/newrelic.cfg:
    pidfile = "/var/run/newrelic/newrelic-daemon.pid"
    port = "/var/run/newrelic/.newrelic.sock"

  10. Add the following line in /etc/cagefs/cagefs.mp:

  11. Add the following to the Alternate PHP directory

    cat << EOF > /opt/alt/php55/etc/php.d.all/newrelic.ini
    extension = "newrelic.so"

    newrelic.enabled = true
    newrelic.license = "${newrelic_license}"
    newrelic.logfile = "/var/log/newrelic/php_agent.log"
    newrelic.appname = "${newrelic_appname}"
    newrelic.daemon.logfile = "/var/log/newrelic/newrelic-daemon.log"
    newrelic.daemon.pidfile = "/var/run/newrelic/newrelic-daemon.pid"
    newrelic.daemon.port = "/var/run/newrelic/.newrelic.sock"
    newrelic.error_collector.enabled = true
    newrelic.error_collector.record_database_errors = false
    newrelic.error_collector.prioritize_api_errors = false
    newrelic.browser_monitoring.auto_instrument = true
    newrelic.transaction_tracer.slow_sql = true
    newrelic.transaction_events.enabled = true
    newrelic.attributes.enabled = true
    newrelic.transaction_events.attributes.enabled = true
    newrelic.transaction_tracer.attributes.enabled = true
    newrelic.error_collector.attributes.enabled = true
    newrelic.browser_monitoring.attributes.enabled = false
    newrelic.custom_insights_events.enabled = true
    newrelic.synthetics.enabled = true

  12. Rebuild Alternate PHP confgurations
    cagefsctl --rebuild-alt-php-ini

  13. Re/start the daemon:
    /etc/init.d/newrelic-daemon restart

  14. Configure the vhosts by creating an Apache New Relic configuration file (change "username" with the appropriate cPanel username)
    1. Create user specific directory
      For Apache 2.2:
          mkdir -p /usr/local/apache/conf/userdata/std/2_2/username/
          mkdir -p /usr/local/apache/conf/userdata/ssl/2_2/username/
      For Apache 2.4:
          mkdir -p /usr/local/apache/conf/userdata/std/2_4/username/
          mkdir -p /usr/local/apache/conf/userdata/ssl/2_4/username/

    2. Create the configuration file (you may replace the master account key with the New  Relic's subaccount key in order to provide New Relic subaccount access to the client)
      For Apache 2.2:
          cat << EOF > /usr/local/apache/conf/userdata/ssl/2_2/username/newrelic.conf
          SetEnv newrelic_appname 'APP name'
          SetEnv newrelic_license 'YOUR LICENSE KEY'
      For Apache 2.4:
          cat << EOF > /usr/local/apache/conf/userdata/ssl/2_4/username/newrelic.conf
          SetEnv newrelic_appname 'APP name'
          SetEnv newrelic_license 'YOUR LICENSE KEY'

  15. Rebuild EasyApache and apply the newly created configuration
    /scripts/ensure_vhost_includes --all-users && service httpd graceful

  16. Remount and forcefully update CageFS containers
    cagefsctl --remount-all && cagefsctl --force-update


To check if it is working, have a look at the log file (Default location is: /var/log/newrelic/newrelic-daemon.log). You should see lines with "Info: Reporting to: https://rpm.newrelic.com"


Credits goes to...

Happy monitoring and tracking!
  • 1883 Users Found This Useful
Was this answer helpful?

Related Articles

How to install a custom BIN on CloudLinux (with CageFS)

CageFS creates a filesystem template in /usr/share/cagefs-skeleton directory. CageFS template...

How to silence a CRON and prevent it to send emails

Problem:Every time that a CRON is running, an email is sent.  Those emails aren't always...

Recommended firewall

What firewall do you recommend to secure my Linux server? MACI recommends the CSF (ConfigServer...

What are .htaccess files and how to create and edit them

.htaccess files are used to configure and provide the server with instuctions regarding the...