Configure PHP application

To automatically instrument a PHP application, use PHP latest version 8.2 or later is required.

Prerequisites: PHP 8.2 or later, Composer, and PHP Extension Community Library (PECL) are installed.

Step 1: Execute below command to build the OpenTelemetry PHP extension.

yum install -y https://rpms.remirepo.net/enterprise/remi-release-$(rpm -E %rhel).rpm
yum install php-cli php-pear php-devel gcc php-grpc -y
yum install gcc make autoconf

Step 2: Use PECL to build the OpenTelemetry PHP extension.

pecl install opentelemetry

Step 3: Add the following code to the php.ini file.

[opentelemetry]
extension=opentelemetry.so

Step 4: Execute below command to verify whether the OpenTelemetry PHP extension is built and enabled.

php -m | grep opentelemetry

Expected output: opentelemetry

Screenshot 1 — Configure PHP application

Step 5: Exceute below command to add additional dependencies required for OpenTelemetry SDK for PHP to perform automatic instrumentation on your application.

composer config allow-plugins.php-http/discovery false

composer require \
open-telemetry/sdk \
open-telemetry/opentelemetry-auto-slim \
open-telemetry/exporter-otlp \
php-http/guzzle7-adapter \
open-telemetry/transport-grpc

Step 6: Run the application with below command.

env OTEL_PHP_AUTOLOAD_ENABLED=true OTEL_SERVICE_NAME=<Server-Name> OTEL_TRACES_EXPORTER=otlp OTEL_METRICS_EXPORTER=none OTEL_LOGS_EXPORTER=none OTEL_EXPORTER_OTLP_PROTOCOL=grpc OTEL_EXPORTER_OTLP_ENDPOINT=http://<Applicare_IP>:4317

Change the value in that variable as below.

<Server_name>= The name of the agent shown in the Applicare console.

<Applicare_IP>= The IP address of the machine running the Applicare controller.

Example: env OTEL_PHP_AUTOLOAD_ENABLED=true OTEL_SERVICE_NAME=rolldice OTEL_TRACES_EXPORTER=otlp OTEL_METRICS_EXPORTER=none OTEL_LOGS_EXPORTER=none OTEL_EXPORTER_OTLP_PROTOCOL=grpc OTEL_EXPORTER_OTLP_ENDPOINT=http://192.168.2.6:4317 php -S 10.0.0.4:8080

Was this article helpful?

Votes and follows are kept by Zendesk, so they need a Help Center account. These buttons open this article there.

Opens Zendesk · needs internet and sign-in

Still stuck? Contact support