elastic / apm-agent-php

Apache License 2.0
252 stars 69 forks source link

Error installing Elastic PHP agent #1092

Open malf88 opened 10 months ago

malf88 commented 10 months ago

Describe the bug I'm trying to install Elastic PHP agent in a container with the image php:8.2.0-fpm and it's giving me the following error:

58.44 Failed. The supported PHP versions are 7.2-8.2. 58.44 Failed. Elastic PHP agent extension is not supported for the existing PHP installation. 58.44 dpkg: error processing package apm-agent-php (--install): 58.44 installed apm-agent-php package post-installation script subprocess returned error exit status 1 58.51 Errors were encountered while processing:

To Reproduce Steps to reproduce the behavior:

  1. Build image com php:8.2.0-fpm installing the extension according to the documentation
    wget https://github.com/elastic/apm-agent-php/releases/download/v1.10.0/apm-agent-php_1.10.0_all.deb && \
    dpkg -i apm-agent-php_1.10.0_all.deb

    and enabling the extension

    
    extension=elastic_apm.so

elastic_apm.server_url=xxxx elastic_apm.service_name="xxxx"



**Expected behavior**
Since the documentation says it supports php 7.2 - 8.2 I expected it to install correctly.
6fears7 commented 9 months ago

Minimum Reproducible:

Dockerfile
`FROM alpine:3.18.4 ENV APM_VERSION=1.10.0 RUN apk add --no-cache supervisor \ nginx \ libsodium \ php82 \ php82-fpm \ php82-session \ php82-opcache \ php82-pecl-redis \ php82-ctype \ php82-exif \ php82-gd \ php82-phar \ php82-fileinfo \ php82-mysqli \ php82-pecl-imagick \ php82-zip \ php82-intl \ php82-simplexml \ php82-iconv \ php82-dom \ php82-curl \ php82-xml \ php82-xmlreader \ php82-openssl \ php82-mbstring \ php82-xmlwriter \ php82-sodium \ php82-ldap \ php82-tokenizer RUN apk --no-cache add --virtual build-dependencies \ git \ alpine-sdk \ curl-dev \ rpm \ && mkdir -p /opt/apm-agent \ && cd /opt/apm-agent \ && curl -v -O https://github.com/elastic/apm-agent-php/releases/download/v${APM_VERSION}/apm-agent-php_${APM_VERSION}_all.apk -L \ && apk add --allow-untrusted /opt/apm-agent/apm-agent-php_${APM_VERSION}_all.apk -vvv \ && apk del build-dependencies`

When you change php81 to php82, the PHP Version returns ".", indicating a failed concatenate.

The function performing this is in post-install.sh:

function php_command() {
    PHP_BIN=$(command -v php)
    ${PHP_BIN} -d memory_limit=128M "$@"
}

This appears to be an issue with php 8.2 and not the Elastic Agent itself. In PHP 8.2, the "php" command is actually "php82", so the environmental variable "PHP_BIN" fails to correctly use the path to the php binary.

1097 is very relevant to this request at this time.

A workaround I made for now is if you're using php82 to ensure you have either a symlink or a copy pointed at /usr/bin/php

hetii commented 8 months ago

Yea... In my alpine image and php8.1 I simply do: ln -s /usr/bin/php81 /usr/bin/php after php installation.