Use Newrelic monitor Linux PHP App Service

Posted by

This post has been republished via RSS; it originally appeared at: Microsoft Tech Community - Latest Blogs - .

When running your PHP application in Azure Linux App Service, you may encounter availability or performance related issues.
PHP New Relic agent is one of the APM tools that can help to provide a better understanding of what may be causing these issues.

This article shows a demonstration of how to use New Relic agent to monitor your PHP application running in Linux App Service.



  • A New Relic account.
  • Azure App Service for Linux with built-in PHP docker image.


Setup and Enable PHP New Relic agent


Create Newrelic API keys

We can get the Newrelic API keys by navigating directly to
Create "Ingest-License" key:



Copy the new create API key, save it in your local notepad. We will use this key later.


Install the PHP Newrelic Agent in the App Service

Go to, login your New Relic, then click "Add more data"


Select PHP in "App monitoring"


Go "Begin Installation" -> "PHP standard installation"




Provide your application name and select "apt".


Newrelic will provide you the installation commands



Let's put all the commands into a bash script file.



echo 'deb newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list
wget -O- | apt-key add -
apt-get update
apt-get -y install newrelic-php5
NR_INSTALL_SILENT=1 newrelic-install install

sed -i -e "s/REPLACE_WITH_REAL_KEY/<your Newrelic API key>/" \
  -e "s/newrelic.appname[[:space:]]=[[:space:]].*/newrelic.appname=\"<your application name>\"/" \
  -e '$anewrelic.distributed_tracing_enabled=true' \
  $(php -r "echo(PHP_CONFIG_FILE_SCAN_DIR);")/newrelic.ini

echo '>>>check /usr/local/etc/php/conf.d/newrelic.ini'
grep newrelic.license /usr/local/etc/php/conf.d/newrelic.ini
grep newrelic.appname /usr/local/etc/php/conf.d/newrelic.ini


1) In line 9, replace <your Newrelic API key> with your Newrelic API key.

     For example:

     sed -i -e "s/REPLACE_WITH_REAL_KEY/9c6fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxNRAL/" \

2) In line 10, replace <your application name> with your Azure App Service name.

    For example:

    -e "s/newrelic.appname[[:space:]]=[[:space:]].*/newrelic.appname=\"myphpwebapp\"/" \

3) To confirm Newrelic being successfully installed, I added Line 14-16 to check newrelic.ini being configured as expected.





In your Azure App Service WEBSSH, create /home/ with the above contents.

Go to https://<your-webapp-name>


vi /home/


Past all the script contents into it, then use ":wq" to save this file.



Go to your App Service Configuration portal to set "Startup Command", point it to your /home/



Enable your "App Service logs"


In your /home/LogFiles/xxxx_xx_xx_xxxxxxxx_default_docker.log file, you will see the Newrelic being installed during the boot up startup.





Monitor your PHP Application Performance in Newrelic

Go to, click "Explorer" tab, in the "APM", we should see your java app showed up in the list. The Name should match your application name defined in your



Monitor the Application performance Summary.



Check Errors and exceptions throwed by the PHP application



Check Service map and dependencies




Check Transactions, analysis most time consuming requests



Check Database performance







This articles are republished, there may be more discussion at the original link. But if you found this helpful, you're more than welcome to let us know!

This site uses Akismet to reduce spam. Learn how your comment data is processed.