From 338c49b68392b25561987a2e5cd06353a5e49958 Mon Sep 17 00:00:00 2001 From: Chris Wharton Date: Tue, 7 Jul 2026 14:18:18 +1200 Subject: [PATCH 1/4] Add static Linux build script. --- build-linux-static.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 build-linux-static.sh diff --git a/build-linux-static.sh b/build-linux-static.sh new file mode 100755 index 0000000000..cdd714477c --- /dev/null +++ b/build-linux-static.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -o errexit +set -x + +# The following environment variables can be passed to docker build and to the build-static.sh script to customize the static build: + # + # FRANKENPHP_VERSION: the version of FrankenPHP to use + # PHP_VERSION: the version of PHP to use + # PHP_EXTENSIONS: the PHP extensions to build (list of supported extensions) + # PHP_EXTENSION_LIBS: extra libraries to build that add features to the extensions + # XCADDY_ARGS: arguments to pass to xcaddy, for instance to add extra Caddy modules + # EMBED: path of the PHP application to embed in the binary + # CLEAN: when set, libphp and all its dependencies are built from scratch (no cache) + # COMPRESS: when set to 1, pack the resulting binary with UPX (Linux only; ignored when DEBUG_SYMBOLS is set) + # DEBUG_SYMBOLS: when set, debug-symbols will not be stripped and will be added to the binary + # MIMALLOC: (experimental, Linux-only) replace musl’s mallocng by mimalloc for improved performance. We only recommend using this for musl targeting builds, for glibc prefer disabling this option and using LD_PRELOAD when you run your binary instead. + # RELEASE: (maintainers only) when set, the resulting binary will be uploaded on GitHub + +# PHP extensions from composer.json +PHP_EXTENSIONS="bcmath,ctype,curl,dom,fileinfo,filter,gd,hash,intl,json,mbstring,openssl,pcre,pdo,session,tokenizer,xml" +PHP_VERSION=8.4 + +# Build the static Linux binary using the musl static builder +docker buildx bake --load \ + --set "*.args.PHP_EXTENSIONS=${PHP_EXTENSIONS}" \ + --set "*.args.PHP_VERSION=${PHP_VERSION}" \ + static-builder-musl + +# Copy the binary out of the container +docker buildx bake --load static-builder-gnu +docker cp $(docker create --name static-builder-gnu dunglas/frankenphp:static-builder-gnu):/go/src/app/dist/frankenphp-linux-$(uname -m) frankenphp +docker rm static-builder-gnu From 51eb7bc440cee5f6cb728ea8288bfa53d9e42bdb Mon Sep 17 00:00:00 2001 From: Chris Wharton Date: Tue, 7 Jul 2026 14:20:57 +1200 Subject: [PATCH 2/4] Update Linux static build script to use glibc instead of musl --- build-linux-static.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/build-linux-static.sh b/build-linux-static.sh index cdd714477c..8c6cbe1c00 100755 --- a/build-linux-static.sh +++ b/build-linux-static.sh @@ -21,13 +21,10 @@ set -x PHP_EXTENSIONS="bcmath,ctype,curl,dom,fileinfo,filter,gd,hash,intl,json,mbstring,openssl,pcre,pdo,session,tokenizer,xml" PHP_VERSION=8.4 -# Build the static Linux binary using the musl static builder -docker buildx bake --load \ - --set "*.args.PHP_EXTENSIONS=${PHP_EXTENSIONS}" \ - --set "*.args.PHP_VERSION=${PHP_VERSION}" \ - static-builder-musl +# build glibc for linux amd64 +docker buildx bake --load static-builder-gnu \ + --set "*.args.PHP_EXTENSIONS=${PHP_EXTENSIONS}" \ + --set "*.args.PHP_VERSION=${PHP_VERSION}" \ -# Copy the binary out of the container -docker buildx bake --load static-builder-gnu docker cp $(docker create --name static-builder-gnu dunglas/frankenphp:static-builder-gnu):/go/src/app/dist/frankenphp-linux-$(uname -m) frankenphp docker rm static-builder-gnu From 13035100a2a091503e2057077866ab24996d9584 Mon Sep 17 00:00:00 2001 From: Chris Wharton Date: Tue, 7 Jul 2026 14:22:59 +1200 Subject: [PATCH 3/4] Refactor Linux static build script to use temporary bake override file for platform restriction --- build-linux-static.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/build-linux-static.sh b/build-linux-static.sh index 8c6cbe1c00..81c5182804 100755 --- a/build-linux-static.sh +++ b/build-linux-static.sh @@ -14,17 +14,31 @@ set -x # CLEAN: when set, libphp and all its dependencies are built from scratch (no cache) # COMPRESS: when set to 1, pack the resulting binary with UPX (Linux only; ignored when DEBUG_SYMBOLS is set) # DEBUG_SYMBOLS: when set, debug-symbols will not be stripped and will be added to the binary - # MIMALLOC: (experimental, Linux-only) replace musl’s mallocng by mimalloc for improved performance. We only recommend using this for musl targeting builds, for glibc prefer disabling this option and using LD_PRELOAD when you run your binary instead. + # MIMALLOC: (experimental, Linux-only) replace musl's mallocng by mimalloc for improved performance. We only recommend using this for musl targeting builds, for glibc prefer disabling this option and using LD_PRELOAD when you run your binary instead. # RELEASE: (maintainers only) when set, the resulting binary will be uploaded on GitHub # PHP extensions from composer.json PHP_EXTENSIONS="bcmath,ctype,curl,dom,fileinfo,filter,gd,hash,intl,json,mbstring,openssl,pcre,pdo,session,tokenizer,xml" PHP_VERSION=8.4 -# build glibc for linux amd64 -docker buildx bake --load static-builder-gnu \ - --set "*.args.PHP_EXTENSIONS=${PHP_EXTENSIONS}" \ - --set "*.args.PHP_VERSION=${PHP_VERSION}" \ +# Create a temporary override bake file to restrict to linux/amd64 only +OVERRIDE_FILE=$(mktemp /tmp/bake-override-XXXXXX.hcl) +cat > "${OVERRIDE_FILE}" <<'EOF' +target "static-builder-gnu" { + platforms = ["linux/amd64"] +} +EOF -docker cp $(docker create --name static-builder-gnu dunglas/frankenphp:static-builder-gnu):/go/src/app/dist/frankenphp-linux-$(uname -m) frankenphp +# Build the static Linux binary using the gnu (glibc) static builder +docker buildx bake --load \ + -f docker-bake.hcl \ + -f "${OVERRIDE_FILE}" \ + --set "*.args.PHP_EXTENSIONS=${PHP_EXTENSIONS}" \ + --set "*.args.PHP_VERSION=${PHP_VERSION}" \ + static-builder-gnu + +rm -f "${OVERRIDE_FILE}" + +# Copy the binary out of the container +docker cp $(docker create --name static-builder-gnu dunglas/frankenphp:static-builder-gnu):/go/src/app/dist/frankenphp-linux-x86_64 frankenphp docker rm static-builder-gnu From ba708221986b2130fe4cf7d4c0e7aa19b91461b6 Mon Sep 17 00:00:00 2001 From: Chris Wharton Date: Tue, 7 Jul 2026 15:20:14 +1200 Subject: [PATCH 4/4] Add GitHub Actions workflow for Linux static binary build and include Redis in PHP extensions --- .github/workflows/build-linux-static.yaml | 39 +++++++++++++++++++++++ .gitignore | 1 + build-linux-static.sh | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build-linux-static.yaml diff --git a/.github/workflows/build-linux-static.yaml b/.github/workflows/build-linux-static.yaml new file mode 100644 index 0000000000..26991911a0 --- /dev/null +++ b/.github/workflows/build-linux-static.yaml @@ -0,0 +1,39 @@ +--- +name: Build Linux static binary + +on: + push: + branches: + - main + paths: + - "build-linux-static.sh" + - "docker-bake.hcl" + - "static-builder-gnu.Dockerfile" + - ".github/workflows/build-linux-static.yaml" + workflow_dispatch: + +permissions: + contents: write + +jobs: + build: + name: Build frankenphp linux/amd64 (glibc) + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v3 + + - name: Build static binary + run: bash build-linux-static.sh + + - name: Upload binary artifact + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + with: + name: frankenphp-linux-amd64 + path: frankenphp + if-no-files-found: error diff --git a/.gitignore b/.gitignore index 0a849e1f21..7b7ee90e5f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ __debug_bin frankenphp.test *.log compile_flags.txt +/frankenphp diff --git a/build-linux-static.sh b/build-linux-static.sh index 81c5182804..9579fe036d 100755 --- a/build-linux-static.sh +++ b/build-linux-static.sh @@ -18,7 +18,7 @@ set -x # RELEASE: (maintainers only) when set, the resulting binary will be uploaded on GitHub # PHP extensions from composer.json -PHP_EXTENSIONS="bcmath,ctype,curl,dom,fileinfo,filter,gd,hash,intl,json,mbstring,openssl,pcre,pdo,session,tokenizer,xml" +PHP_EXTENSIONS="bcmath,ctype,curl,dom,fileinfo,filter,gd,hash,intl,json,mbstring,openssl,pcre,pdo,redis,session,tokenizer,xml" PHP_VERSION=8.4 # Create a temporary override bake file to restrict to linux/amd64 only