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.
Prerequisites
- 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 https://one.newrelic.com/launcher/api-keys-ui.api-keys-launcher
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 https://one.newrelic.com/, 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.
#!/bin/bash
echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list
wget -O- https://download.newrelic.com/548C16BF.gpg | 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/setupNewrelic.sh with the above contents.
Go to https://<your-webapp-name>.scm.azurewebsites.net/webssh/host
vi /home/setupNewrelic.sh
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/setupNewrelic.sh
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 https://one.newrelic.com/, 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 setupNewrelic.sh.
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
Posted at https://sl.advdat.com/322MTYw