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:
- Login via ssh as root
- Install New Relic System Monitor and PHP RPM using the official documentation
(from the official doc)- Adding the repo
rpm -Uvh https://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
- Install the packages
yum install newrelic-sysmond newrelic-php5 -y
- Add your New Relic key
nrsysmond-config --set license_key=YOUR_LICENSE_KEY - Start the System Monitoring daemon
/etc/init.d/newrelic-sysmond start - Let's run the auto-installer for PHP
newrelic-install
(choose /usr/local/bin when asked)
- Adding the repo
- Install PHP module in Alternate PHP
- 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 - Uncompress the archive
tar zxvf newrelic-php5-6.4.0.163-linux.tar.gz - 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
- Download the latest modules from the official website (https://download.newrelic.com/php_agent/release/)
- Find out NewRelic group ID
id -g newrelic - 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 - Reload the configuration
sysctl -p - Append the user "newrelic" to the file /etc/cagefs/exclude/systemuserlist
echo "newrelic" >> /etc/cagefs/exclude/systemuserlist - Move /etc/newrelic/newrelic.cfg.template to /etc/newrelic/newrelic.cfg
mv /etc/newrelic/newrelic.cfg.template /etc/newrelic/newrelic.cfg - Add/Modify the following lines in /etc/newrelic/newrelic.cfg:
pidfile = "/var/run/newrelic/newrelic-daemon.pid"
port = "/var/run/newrelic/.newrelic.sock" - Add the following line in /etc/cagefs/cagefs.mp:
/var/run/newrelic - 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 - Rebuild Alternate PHP confgurations
cagefsctl --rebuild-alt-php-ini - Re/start the daemon:
/etc/init.d/newrelic-daemon restart - Configure the vhosts by creating an Apache New Relic configuration file (change "username" with the appropriate cPanel username)
- 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/ - 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
- Create user specific directory
- Rebuild EasyApache and apply the newly created configuration
/scripts/ensure_vhost_includes --all-users && service httpd graceful - 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/