As you may or may not know Magento has a Newrelic reporting module built in, that is free to use. The only requirement is the Newrelic php extension. (This is different to a Magento extension.) Fortunatley MDOQ has you covered. Newrelic is installed by default, you just need to carry out a few steps to enable it. In this guide you will see how to enable the Newrelic php extension for your Magento site.
1. Create an instance
As with everything MDOQ the first thing are going to do is create an instance to test our work on.
2. Enable / Configure Newrelic
2.1 Enable the php extension (for PHP-FPM and cli)
Open vscode for your instance and edit the file `mdoq/php-fpm/configure`.
If this file doesn't exist, create it with the following content
#!/bin/bash -xe
# configure new relic
mv /etc/php/${PHP_VERSION}/cli/conf.d/newrelic.ini.disabled /etc/php/${PHP_VERSION}/cli/conf.d/newrelic.ini || true
mv /etc/php/${PHP_VERSION}/fpm/conf.d/newrelic.ini.disabled /etc/php/${PHP_VERSION}/fpm/conf.d/newrelic.ini || true
supervisorctl restart php-fpm
Then open a terminal and make sure this file is executable, just run
chmod a+x mdoq/php-fpm/configure
Then open the settings for your instance and navigate to PHP-FPM, you need to ensure:
- Post rollup commands contains `cd /home/magento/htdocs; ./mdoq/php-fpm/configure;`
- Run command as is `root`
(If you made any changes, save them, but don't let MDOQ recreate the components.
2.2 Enable the php extension (for cron)
Open the settings for your instance and navigate to Cron.
Add an Aditional Cron Job
Set the User to `root`
Set the Cron Expression to `*/10 * * * *`
Set the Command to `mv /etc/php/${PHP_VERSION}/cli/conf.d/newrelic.ini.disabled /etc/php/${PHP_VERSION}/cli/conf.d/newrelic.ini || true`
Save your changes, but again don't allow MDOQ to recreate the components.
2.3 Configure App Name per instance
This step is optional, but if you are using MDOQ having each instance report under a different app name will help a lot.
In your post roll up actions, add the following under the "Final" step
if [ ${MDOQ_INSTANCE_TYPE} == "bug" ]; then
php bin/magento config:set -- newrelicreporting/general/app_name "Magento - ${MDOQ_INSTANCE_TICKET_NUMBER}"
fi;
This will look something like:
"$ARGUMENT_STEP_FINAL-"*)
# other steps / commands
if [ ${MDOQ_INSTANCE_TYPE} == "bug" ]; then
php bin/magento config:set -- newrelicreporting/general/app_name "Magento - ${MDOQ_INSTANCE_TICKET_NUMBER}"
fi;
# other steps / commands
;;
2.4 Apply the change
You will now be good to synchronize instance components to get the changes to take effect.
At a minimum you will need to synchronize:
- php-fpm
- cron
- post roll up actions
Though you could just choose to synchronize all.
3. Configure Newrelic reporting
You will now be able to configure reporting within the admin.
See steps 1,3 & 4 at New Relic Reporting
4. Test / Submit work
Once you are happy it is all working as expected you can submit your work to source control. This will likely mean commiting:
- mdoq/php-fpm/configure
- mdoq/post_roll_up_actions
You can then follow the normal "I'm Done" process to create a deployment.
5. Deploying the work
We recommend the following order for deploying this work to production.
- Update the cron and php-fpm settings for the production instance. (See Step 2.1 and Step 2.2)
- Deploy your work as a zero downtime deployment
- Open the synchronize menu for production
Select "Show more"
Check Cron, PHP-FPM and SSH
Select "Enable Advanced Mode"
Check "Only synchronize selected components"
Click "Synchronize"
(N.B there will be some downtime whilst PHP-FPM recreates) - Configure Newrelic from within the admin, see Step 3.
All done, enjoy Newrelic!