Skip to content

Instantly share code, notes, and snippets.

@tonybolzan
Last active November 29, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonybolzan/fbeb28fdf1400e9a00926884eea97e11 to your computer and use it in GitHub Desktop.
Save tonybolzan/fbeb28fdf1400e9a00926884eea97e11 to your computer and use it in GitHub Desktop.
NewRelic Installer for x64 glibc linux system without PHP ZTS
#!/bin/bash
set -euo pipefail
# NewRelic Installer for x64 glibc linux system without PHP ZTS
# Tested on debian:buster-slim
INSTALL_DIR=$(mktemp -d -t)
PHP_VER=$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')
PHP_DIR=$(php -r 'echo ini_get("extension_dir");')
PHP_API=${PHP_DIR##*/}
cd "$INSTALL_DIR"
echo "NewRelic - Downloading"
php -r '$matches=""; preg_match("/newrelic-php.*?linux.tar.gz/", file_get_contents("https://download.newrelic.com/php_agent/release/"), $matches); if (empty($matches[0] ?? "")) { exit(1); } else { readfile("https://download.newrelic.com/php_agent/release/$matches[0]"); };' > newrelic.tar.gz
echo "NewRelic - Unpacking"
tar -xzf newrelic.tar.gz
rm -f newrelic.tar.gz
cd newrelic-php*
echo "NewRelic - Validating"
if [ ! -f "./agent/x64/newrelic-$PHP_API.so" ]; then
>&2 echo "NewRelic don't suport this php api version $PHP_API"
exit 1
fi
echo "NewRelic - Installing"
cp -f "./agent/x64/newrelic-$PHP_API.so" "$PHP_DIR/newrelic.so"
cp -f "./daemon/newrelic-daemon.x64" "/usr/bin/newrelic-daemon"
mkdir /var/log/newrelic
chmod 755 /var/log/newrelic
cat > "/etc/php/$PHP_VER/mods-available/newrelic.ini" <<'EOF'
extension = newrelic.so
[newrelic]
newrelic.license = ""
newrelic.appname = ""
newrelic.capture_params = On
newrelic.logfile = /var/log/newrelic/agent.log
newrelic.daemon.logfile = /var/log/newrelic/daemon.log
EOF
phpenmod -v ALL -s ALL newrelic
if [[ `php -r 'echo extension_loaded("newrelic") ? 1 : 0;'` -le 0 ]]; then
>&2 echo "NewRelic - Extension not installed"
exit 1
fi
phpdismod -v ALL -s ALL newrelic
echo "NewRelic - Test OK"
cd /
rm -rf "$INSTALL_DIR"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment