How to configure apm agent for multiple php sites on one machine

Follow this page Configuration | APM PHP Agent Reference [1.x] | Elastic
It is easy to configure apm agent for one php site on the machine by configuring php.ini, but if I have multiple php apps on one machine, how should I differentiate the service_name of different apps

That's a great question @lhb6540 -- at a high level you'll want to have each application set a different value for the service_name via different php.ini files or another of PHP's mechanisms for setting ini variables. How you'll do this will depend on how you're running PHP.

If you're not sure how to set ini values, we can help with that if you can answer a few questions. Do you know if you're running PHP via an Apache module (mod_php)? Or are you using PHP-FPM? Or maybe something newer like swoole? Let us know and we'll get you the information you need to get up and running with as many apps as you want :slight_smile:

I use php-fpm 7.4 on centos7
I configured nginx in front of multiple sites and forwarded to localhost:9000 via fastcgi
My php configuration file directory is /etc/opt/remi/php74/php.ini (I configure elastic agent related information here), and the php-fpm configuration file directory is /etc/opt/remi/php74/php -fpm.d/www.conf

Thanks for that information @lhb6540!

Since you're using PHP-FPM your best bet will be to take advantage of PHP's .user.ini files. These files allow you to set php.ini configuration values on a per directory basis, and should allow you to set a different elastic_apm.service_name value for each of your applications (as outlined in the PHP Agent docs)

If you need more information please let us know. Otherwise good luck with your sites/apps and thanks for giving Elastic APM a spin.

1 Like

Thanks,this method solved the problem

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.