Docker-php-ext-install error with cimg/php:8.3

Is CircleCI blocked by PHP Mirrors? I am getting 503 when installing the docker-php-ext-install.

@circleci-community please help in understanding that I am able to call the URL https://www.php.net/distributions/php-8.3.30.tar.xz but in CircleCI job it is giving errors.

^@^@curl: (22) The requested URL returned error: 503 /usr/local/bin/docker-php-ext-install: line 19: cd: /usr/src/php/ext: No such file or directory Exited with code exit status 1

2 Likes

+1 on this. We are using the cimg/php:7.4 image (lots of back-compat testing) and get the same problem.

Our job runs docker-php-ext-install zip

The docker-php-ext-install script in the image runs docker-php-source extract, which should be doing curl -fsSL -o php.tar.xz https://www.php.net/distributions/php-7.4.33.tar.xz

Running the curl command locally works fine. But we are seeing the 503 error in CircleCI.

We also suspect that CircleCI has been blocked by php.net

I note that a similar issue has been raised on the PHP.net GitHub repo: IP Rate limited from https://www.php.net/releases/index.php?json · Issue #1844 · php/web-php · GitHub

+1.

I found this issue too.

Tried switching images doesn’t help.

  • cimg/php:8.4.18-node
  • cimg/php:8.4-node

Also tried switching resource_class doesn’t help too.

The error:

curl: (22) The requested URL returned error: 503
/usr/local/bin/docker-php-ext-configure: line 19: cd: /usr/src/php/ext: No such file or directory

I ended up by compiling from scratch using the custom script. Sharing here if someone needs a quick solution.

#!/usr/bin/env bash
set -euo pipefail
​
echo "PHP_VERSION=$(php -r 'echo PHP_VERSION;')"
​
# If source already exists (e.g., restored from cache), stop here.
if [ -d /usr/src/php/ext ]; then
  echo "/usr/src/php/ext already present, skipping download"
  exit 0
fi
​
# Keep a copy of the original script once per job container
if [ ! -f /usr/local/bin/docker-php-source.orig ]; then
  sudo cp /usr/local/bin/docker-php-source /usr/local/bin/docker-php-source.orig
fi
​
# Install wrapper. This is in a repo file, so CircleCI config parsing won't care about the heredoc.
sudo tee /usr/local/bin/docker-php-source >/dev/null <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
​
cmd="${1:-}"
​
PHP_VER="$(php -r "echo PHP_VERSION;")"
PRIMARY="https://www.php.net/distributions/php-${PHP_VER}.tar.xz"
FALLBACK1="https://www.php.net/get/php-${PHP_VER}.tar.xz/from/this/mirror"
FALLBACK2="https://downloads.php.net/~phpweb/php-${PHP_VER}.tar.xz"
FALLBACK3="https://github.com/php/php-src/archive/refs/tags/php-${PHP_VER}.tar.gz"
​
download() {
  local url="${1:?missing url}"
  echo "Downloading: ${url}"
​
  rm -f /tmp/php.tar.xz /tmp/php.tar.gz
​
  if echo "${url}" | grep -qE '\.tar\.xz($|\?)'; then
    curl -4 -fL --retry 8 --retry-all-errors --retry-delay 2 -o /tmp/php.tar.xz "${url}"
  else
    curl -4 -fL --retry 8 --retry-all-errors --retry-delay 2 -o /tmp/php.tar.gz "${url}"
  fi
}
​
extract_source() {
  sudo rm -rf /usr/src/php
  sudo mkdir -p /usr/src/php
​
  if [ -f /tmp/php.tar.xz ]; then
    sudo tar -xJf /tmp/php.tar.xz -C /usr/src/php --strip-components=1
  elif [ -f /tmp/php.tar.gz ]; then
    sudo tar -xzf /tmp/php.tar.gz -C /usr/src/php --strip-components=1
  else
    echo "No PHP source archive found in /tmp"
    exit 1
  fi
​
  test -d /usr/src/php/ext
}
​
case "${cmd}" in
  extract)
    echo "docker-php-source extract: PHP_VER=${PHP_VER}"
    echo "Trying: ${PRIMARY}"
    echo "Fallback: ${FALLBACK1}"
    echo "Fallback: ${FALLBACK2}"
    echo "Fallback: ${FALLBACK3}"
​
    if [ -d /usr/src/php/ext ]; then
      echo "/usr/src/php already present"
      exit 0
    fi
​
    download "${PRIMARY}" \
      || download "${FALLBACK1}" \
      || download "${FALLBACK2}" \
      || download "${FALLBACK3}"
​
    extract_source
    ;;
  delete)
    sudo rm -rf /usr/src/php /tmp/php.tar.xz /tmp/php.tar.gz || true
    ;;
  *)
    exec /usr/local/bin/docker-php-source.orig "$@"
    ;;
esac
EOF
​
sudo chmod +x /usr/local/bin/docker-php-source
​
# Force extraction now so failures are explicit
docker-php-source extract

This issue shall be fixed with this PR

Awesome work, @cleverrocks . Thank you.