This page is pulled from project's readme. Links could be broken.

Ansible Role GitHub tag (latest SemVer) Ansible Role CircleCI Ansible Quality Score GitHub GitHub Sponsor Sponsor via PayPal Hire Typist Tech Twitter Follow @TangRufus

Install New Relic PHP agent on Trellis servers.

Role Variables

# group_vars/<environment>/vault.yml
# This file should be encrypted. See: https://roots.io/trellis/docs/vault/
##########################################################################

# New Relic License Key
## See: https://docs.newrelic.com/docs/accounts-partnerships/accounts/account-setup/license-key
vault_newrelic_license: xxxxxxxxxxx

# group_vars/<environment>/main.yml
###################################

# Indicates the desired package state.
# `latest` ensures that the latest version is installed.
# `present` does not update if already installed.
# Choices: present|latest
# Default: latest
newrelic_package_state: present

# Check for default values here: https://github.com/TypistTech/trellis-newrelic-php/blob/master/defaults/main.yml
# See also: https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-configuration
newrelic_config:
  appname: "My Awesome App {{ env }}"
  framework: no_framework
  transaction_tracer.detail: 1
  datastore_tracer.database_name_reporting.enabled: true

Hacking Trellis' Playbook

Add this role to dev.yml and server.yml immediately after role: php:

  # `dev.yml` & `server.yml`

  roles:
      # Some other Trellis roles ...
      - { role: php, tags: [php] }
+     - { role: TypistTech.trellis-newrelic-php, tags: [php, newrelic-php] }
      # Some other Trellis roles ...

Requirements

Installation

Add this role to requirements.yml:

- src: TypistTech.trellis-newrelic-php # Case-sensitive!
  version: XXX.YYY.ZZZ # Check for latest version!

Run $ ansible-galaxy install -r requirements.yml to install this new role.

Common Errors

vault_newrelic_license is not defined

Encrypt your New Relic license key in group_vars/<environment>/vault.yml. See role variables.

New Relic merges multiple environments into single application

Solution: Define different appname for different environments.

Tips:

# group_vars/all/main.yml
#########################

newrelic_config:
  appname: "My Awesome App {{ env }}"

Error after upgrading PHP version

New Relic would fail and causes provision end up in errors when upgrading PHP minor releases (e.g: from 7.3 to 7.4).

non-zero return code
PHP Warning:  PHP Startup: Unable to load dynamic library 'newrelic.so'
(tried: /usr/lib/php/20180731/newrelic.so (/usr/lib/php/20180731/newrelic.so:
cannot open shared object file: No such file or directory),
/usr/lib/php/20180731/newrelic.so.so (/usr/lib/php/20180731/newrelic.so.so:
cannot open shared object file: No such file or directory)) in Unknown on

After PHP minor release upgrade (i.e: when you see the above error):

ssh [email protected]
sudo newrelic-install install
sudo reboot

# Wait for server reboot and then re-provision
trellis provision production
# Alternatively
ansible-playbook server.yml -e env=production

Limitations

  • Only one New Relic APM application per server by default.

Extends the fastcgi_basic block to include fastcgi_param PHP_VALUE "newrelic.appname={{ item.key }} ({{ env }})"; right after the line include fastcgi_params; to work around this limitation.

Pull requests are welcomed.

FAQs

It looks awesome. Where can I find some more goodies like this?

This package isn't on wp.org. Where can I give a :star::star::star::star::star: review?

Thanks! Glad you like it. It's important to let me know somebody is using this project. Since this is not hosted on wordpress.org, please consider:

Sponsoring :heart:

Love trellis-newrelic-php? Help me maintain it, a sponsorship here can help with it.

GitHub Sponsors Matching Fund

Do you know GitHub is going to match your sponsorship?

Sponsor now via GitHub to double your greatness.

Why don't you hire me?

Ready to take freelance WordPress jobs. Contact me via the contact form here or, via email [email protected]

Want to help in other way? Want to be a sponsor?

Contact: Tang Rufus

Running the Tests

Run the tests:

ansible-playbook -i 'localhost,' --syntax-check tests/test.yml
ansible-lint tests/test.yml

Feedback

Please provide feedback! We want to make this library useful in as many projects as possible. Please submit an issue and point out what you do and don't like, or fork the project and make suggestions. No issue is too small.

Change log

Please see CHANGELOG for more information on what has changed recently.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

Trellis New Relic PHP Agent is a Typist Tech project and maintained by Tang Rufus, freelance developer for hire.

Full list of contributors can be found here.

Special thanks to the Roots team whose Trellis make this project possible.

Contributing

Please see CODE_OF_CONDUCT for details.

License

Trellis New Relic PHP Agent is released under the MIT License.