Knowledgebase

[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-6.4.0.163-linux.tar.gz

    2. Uncompress the archive
      tar zxvf newrelic-php5-6.4.0.163-linux.tar.gz

    3. Copy the module to the proper directories
      cp ~/newrelic-php5-6.4.0.163-linux/agent/x64/newrelic-20121212.so /opt/alt/php54/usr/lib64/php/modules/newrelic.so
      cp ~/newrelic-php5-6.4.0.163-linux/agent/x64/newrelic-20121212.so /opt/alt/php55/usr/lib64/php/modules/newrelic.so
      cp ~/newrelic-php5-6.4.0.163-linux/agent/x64/newrelic-20131226.so /opt/alt/php56/usr/lib64/php/modules/newrelic.so
      cp ~/newrelic-php5-6.4.0.163-linux/agent/x64/newrelic-20151012.so /opt/alt/php70/usr/lib64/php/modules/newrelic.so
      cp ~/newrelic-php5-6.4.0.163-linux/agent/x64/newrelic-20151012.so /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:
    /var/run/newrelic

  11. Add the following to the Alternate PHP directory

    ## COPY & PASTE THE WHOLE SNIPET ##
    cat << EOF > /opt/alt/php55/etc/php.d.all/newrelic.ini
    [newrelic]
    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
    EOF

  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)
      ## COPY & PASTE THE WHOLE SNIPPET AND ADJUST THE USERNAME, KEY & APP NAME##
      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'
          EOF
      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'
          EOF

  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...
https://docs.newrelic.com/docs/agents/php-agent/installation/php-agent-installation-redhat-centos
https://www.lucasrolff.com/cpanel/new-relic-and-cloudlinux/

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