Skip to content

[Bug]: post-install.sh does not detect the 'json' extension on PHP 8.1.29 #2704

@wslyhbb

Description

@wslyhbb

Bug report

post-install.sh does not detect the json extension on Alpine with PHP 8.1.29. As shown in the php -m listing below, the json extension is installed but post-install.sh cannot detect it:

PHP 8.1.29 (cli) (built: Jun  6 2024 17:00:13) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.29, Copyright (c) Zend Technologies
### Installing Datadog PHP tracing extension (ddtrace)
###
### Logging /usr/bin/php -i to a file
###
lib/apk/exec/datadog-php-tracer-0.99.1.post-install: line 46: -d: command not found
lib/apk/exec/datadog-php-tracer-0.99.1.post-install: line 46: -d: command not found
lib/apk/exec/datadog-php-tracer-0.99.1.post-install: line 46: -d: command not found
lib/apk/exec/datadog-php-tracer-0.99.1.post-install: line 46: -d: command not found
lib/apk/exec/datadog-php-tracer-0.99.1.post-install: line 46: -d: command not found
Checking for extension: json
lib/apk/exec/datadog-php-tracer-0.99.1.post-install: line 46: -d: command not found
Error: PHP extension 'json' was not found.
ERROR: datadog-php-tracer-0.86.2.post-install: script exited with error 1

Issue is with detecting PHP version (lines 25-38):

# We attempt in this order the following binary names:
#    1. php
#    2. php8 (some alpine versions install php 8.x from main repo to this binary)
#    3. php7 (some alpine versions install php 7.x from main repo to this binary)
#    4. php5 (some alpine versions install php 5.x from main repo to this binary)
if [ -z "$DD_TRACE_PHP_BIN" ]; then
    DD_TRACE_PHP_BIN=$(command -v php || true)
fi
if [ -z "$DD_TRACE_PHP_BIN" ]; then
    DD_TRACE_PHP_BIN=$(command -v php8 || true)
fi
if [ -z "$DD_TRACE_PHP_BIN" ]; then
    DD_TRACE_PHP_BIN=$(command -v php7 || true)
fi

I think DD_TRACE_PHP_BIN is not getting set because /usr/bin/php8 does not exist. The folder is /usr/bin/php81 and the code is not looking for that.
Symbolically linking php81 to php8 prior to installing the tracer fixes the issue:
ln -s /usr/bin/php81 /usr/bin/php8

PHP version

PHP 8.1.29 (cli) (built: Jun 6 2024 17:00:13) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.29, Copyright (c) Zend Technologies

Tracer or profiler version

datadog-php-tracer_0.99.1_x86_64.apk

Installed extensions

[PHP Modules]
Core
ctype
curl
date
dom
exif
fileinfo
filter
gd
hash
iconv
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
Phar
readline
Reflection
session
SimpleXML
sodium
SPL
standard
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

Output of phpinfo()

NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.19.1
PRETTY_NAME="Alpine Linux v3.19"

Upgrading from

PHP 8.1.27

Metadata

Metadata

Assignees

No one assigned

    Labels

    cat:installationIssues while installing the tracer🐛 bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions