How to install New Relic Agent in Google App Engine Flexible Environment


New Relic provides Application Performance Monitoring (APM) for a lot of platforms (AWS, Heroku, etc.) and frameworks (Symphony, Magento, etc.), but there is no much information on the internet so far about steps to install New Relic Agent in Google App Engine (GAE) Flexible Environment (Flex Env), so I did try installing successfully on my production project and then will talk about it here.

Step 1: Create a custom docker image based on Google cloud platform php docker, php nginx image — on local (i.e. mac)


# A shell script for installing New Relic agent.
set -xe

DEBIAN_FRONTEND=noninteractive echo 'deb newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list

DEBIAN_FRONTEND=noninteractive apt-get -y install wget
DEBIAN_FRONTEND=noninteractive wget -O- | apt-key add -

DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y vim less
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends apt-utils

DEBIAN_FRONTEND=noninteractive apt-get install -yq newrelic-php5
DEBIAN_FRONTEND=noninteractive newrelic-install install


# Setup environment variables for initializing New Relic
RUN /bin/bash /build-scripts/

Step 2: Build, tag and upload to Google Cloud Storage (work under application directory) — on local (i.e. mac)

docker build -t php-nginx-new_relic .
docker tag php-nginx-new_relic
gcloud docker -- push

Step 3: Deploy your project to Google App Engine Flexible Environment — on local (i.e. mac)

gcloud app deploy app.yaml --project project-id --verbosity debug || exit $?



Step 4: ssh to the GAE Flex Env instance and enter docker container — remote GAE Flex Env instance

(Tips: SSH button is located in Google Cloud Platform dashboard, App Engine page, instances sub page, then click the SSH button will let you ssh to the instance)

Step 5: enter docker container — remote GAE Flex Env instance

sudo docker exec -t -i gaeapp /bin/bash

Step 6Install New Relic with installation script manually — remote GAE Flex Env instance docker container gaeapp

wget -r -l1 -nd -A"linux.tar.gz"

gzip -dc newrelic*.tar.gz | tar xf -

cd newrelic-php5*

rm -f /opt/php56/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20131226/

cp ./agent/x64/ /opt/php56/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20131226/

cp ./daemon/newrelic-daemon.x64 /usr/bin/newrelic-daemon

(Set your license key and application name. Be sure to replace yourLicenseKey and yourApplicationName with your real license key and the app name you desire.)

sed -i -e 's/"REPLACE_WITH_REAL_KEY"/yourLicenseKey/g' ./scripts/newrelic.ini.template

sed -i -e 's/PHP Application/yourApplicationName/g' ./scripts/newrelic.ini.template

(((cp ./scripts/newrelic.ini.template /opt/php56/lib/ext.enabled:/opt/php56/lib/conf.d:/app/newrelic.ini, it’s suggested by New Relic but complained error for me, so I separate into 3 steps as following)))

cp ./scripts/newrelic.ini.template /opt/php56/lib/ext.enabled/newrelic.ini

cp ./scripts/newrelic.ini.template /opt/php56/lib/conf.d/newrelic.ini

cp ./scripts/newrelic.ini.template /app/newrelic.ini

/usr/bin/newrelic-daemon start

Step 7: Restart everything and reload the page
kill -HUP 1
(Restart your webserver and reload this page. If New Relic is loaded you should see a congratulatory message.)
Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.
Caveat and tips:

1. Copy paste in GAE Flex Env docker container: tips to scroll and copy at GAE instance docker container (for debugging by view text file with vim which was configured to install in php-nginx Dockerfile if you need vim)

Mac touchpad to select all in the current screen and use Fn+Shift+Down to go up to previous screen and select again with touchpad until select all content in the text file
2. New Relic to monitor Docker container application
3. dockerizing a php application
4. If you want to install New Relic agent in pure automatic way:

Use runtime:custom and add required piece in your Dockerfile, except for the `/usr/bin/newrelic-daemon start` line.
Then have a file named `additional-supervisord.conf` with the following:



command = /usr/bin/newrelic-daemon -f

stdout_logfile = /dev/stdout


stderr_logfile = /dev/stderr


user = root

autostart = true

autorestart = true

priority = 5

stopwaitsecs = 20


5. If you install New Relic on CentOS, rpm installation doesn’t work for me, but yum and tar ball file work for me and the command should be

./newrelic-install install




as the doc:


About liyao13

Yao Li is a web and iOS developer, blogger and he has a passion for technology and business. In his blogs, he shares code snippets, tutorials, resources and notes to help people develop their skills. Donate $5 to him for a coffee with PayPal at About Me page and read more professional and interesting technical blog articles. Follow him @Yaoli0615 at Twitter to get latest tech updates.
This entry was posted in CS Research&Application, Uncategorized and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s