• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Custom Plesk PHP Template & Fast CGI: How to set New Relic App Name?

AbramS

Basic Pleskian
I'm running Plesk 12 (latest build) on CentOs 6.6 with PHP as FastCGI. I've been using New Relic to monitor PHP and server activity since I started working with Plesk and it has always worked great, and it still does.

By default the New Relic config grabs all PHP activity as one 'Application' through the newrelic.appname variable that is set in /etc/php.d/newrelic.ini. The default appname is 'PHP Application'.

Now the awesome thing is, that you can specify a per domain AppName, allowing you to monitor server activity and per site activity for PHP. I've tested this through the 'PHP Additional Directives' feature in Plesk, which allows me to define newrelic.appname on a per domain basis. This works great, but locks that site from syncing with the subscription, as you're customising the setup. So: it works for NewRelic, but it makes managing subscriptions a pain in the ***.

Fortunately different Plesk users created a workaround for this by using custom service templates for Plesk. The solution for Plesk 11 is to create a file called php.php inside /usr/local/psa/admin/conf/templates/custom/service/ with the following content:

Code:
<IfModule <?php echo $VAR->server->webserver->apache->php4ModuleName ?>>
<?php
if ($OPT['enabled']) {
    echo "php_admin_flag engine on\n";
    if (isset($OPT['settings'])) {
        echo $OPT['settings'];
    }
} else {
    echo "php_admin_flag engine off\n";
}
?>
<?php
if (isset($VAR->domain))
{
    echo "php_value newrelic.appname '".$VAR->domain->idnName."'\n";
}
?>
</IfModule>

<IfModule mod_php5.c>
<?php
if (array_key_exists('enabled', $OPT) && $OPT['enabled']) {
    echo "php_admin_flag engine on\n";
    if (isset($OPT['settings'])) {
        echo $OPT['settings'];
    }
} else {
    echo "php_admin_flag engine off\n";
}
?>
<?php
if (isset($VAR->domain))
{
    echo "php_value newrelic.appname '".$VAR->domain->idnName."'\n";
}
?>
</IfModule>

<IfModule mod_fcgid.c>
<?php
if (isset($VAR->domain))
{
    echo "php_value newrelic.appname '".$VAR->domain->idnName."'\n";
}
?>
</IfModule>

After creating that file one needs to run a httpdmng --reconfigure-all and from that moment on all domains should report to NewRelic with the Domain Name as the newrelic.appname.

For whatever reason, this does not work in Plesk 12.

I then went into the /usr/local/psa/admin/conf/templates/default/service/ directory and copied all PHP related files to the custom/service directory. These additional files are: php_over_cgi.php, php_over_fastcgi.php and mod_fastcgi.php

As I'm running PHP through FastCGI, I figured that adding the same modifications to the <IfModule> declarations in those files would allow me to get the preferred results.... But after running another httpdmng --reconfigure-all, nothing changed... I kept comparing phpinfo files on two separate domains with different subscriptions, but both kept displaying 'PHP Application' as the default newrelic.appname. Again: changing this in the PHP additional directives of the domain, instantly updated the value to display the correct app name!

Finally: adding this piece of code:

Code:
<?php
if (isset($VAR->domain))
{
    echo "php_value newrelic.appname '".$VAR->domain->idnName."'\n";
}
?>

to the <IfModule fcgi> in custom/domain/domainVirtualHost.php does grab the correct local PHP value IF you run PHP as an Apache module. So the code does seem to work under some settings in Plesk 12, but not with the combination of Plesk 12 and PHP as Fast CGI. How does one get it to work?

So what am I missing here? Which files should I alter in Plesk 12 and how should I alter them if I wish to dynamically populate the newrelic.appname value based on the domain name while running PHP as FastCGI?

Alternatively: Is there maybe a trick to populate the 'PHP additional directives' with a dynamic php_value that allows me to keep the subscriptions in sync?

Thank you for taking the time to think along and help fix this!
 
Last edited:
Has anyone been able to get something like this setup on their servers? I'm really stuck with this...
 
Has anyone been able to get something like this setup on their servers? I'm really stuck with this...

Sorry for the late response, but what i did to fix this, is add

newrelic.appname = "{DOCROOT}"
to the Additional PHP directives in the Service Templates.
It's not that pretty in the NewRelic interface (you'll see all your apps as /var/www/vhosts/domainname.tld/httpdocs), but at least you have the abbility to filter there.
It would be awesome if Plesk implemented a new Variable you can use for these kind of settings, something like {SUBSCRIPTION}
 
Back
Top