Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-2275

PHP version check in configure fails on Alpine

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.17.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      The PHP version check in config.m4 yields an

      if test -z "$PHP_MONGODB_PHP_VERSION"; then
        if test -z "$PHP_CONFIG"; then
          AC_MSG_ERROR([php-config not found])
        fi
        PHP_MONGODB_PHP_VERSION=`${PHP_CONFIG} --version`
        PHP_MONGODB_PHP_VERSION_ID=`echo "${PHP_MONGODB_PHP_VERSION}" | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 100 + [$]2) * 100 + [$]3;}'`
      fi
      
      AC_MSG_RESULT($PHP_MONGODB_PHP_VERSION)
      if test "$PHP_MONGODB_PHP_VERSION_ID" -lt "70200"; then
        AC_MSG_ERROR([not supported. Need a PHP version >= 7.2.0 (found $PHP_MONGODB_PHP_VERSION)])
      fi
      

      When running configure on php:8.1-alpine, the following output is observed:

      checking PHP version... 8.1.22
      sh: out of range
      checking whether to enable developer build flags... no
      

      The "out of range" error likely originates from the test "$PHP_MONGODB_PHP_VERSION_ID" -lt "70200" statement, and suggests that PHP_MONGODB_PHP_VERSION_ID is not computed correctly by the awk one-liner above.


      Note: after investigating this further, we determined that the problem is not related to the awk one-liner. Rather, PHP Docker images for Alpine happen to define PHP_VERSION in their shell, but not PHP_VERSION_ID. The conditional in our config.m4 assumed that PHP_VERSION_ID would be defined alongside PHP_VERSION, which is typically only the case when doing a static build of PHP, since those values are derived from php-src's configure.ac.

      The fix entailed changing the logic to always derive PHP_VERSION and PHP_VERSION_ID from php-config, as is done in other extensions (e.g. xdebug, parallel).

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: