Files
frankenphp/docs/static.md
2023-11-30 08:07:39 +01:00

2.4 KiB

Create a Static Build

Instead of using a local installation of the PHP library, it's possible to create a static build of FrankenPHP thanks to the great static-php-cli project (despite its name, this project support all SAPIs, not only CLI).

With this method, a single, portable, binary will contain the PHP interpreter, the Caddy web server and FrankenPHP!

Linux

We provide a Docker image to build a Linux static binary:

docker buildx bake --load static-builder
docker cp $(docker create --name static-builder dunglas/frankenphp:static-builder):/go/src/app/dist/frankenphp-linux-$(uname -m) frankenphp ; docker rm static-builder

The resulting static binary is named frankenphp and is available in the current directory.

If you want to build the static binary without Docker, take a look at the macOS instructions, which also works for Linux.

Custom Extensions

By default, most popular PHP extensions are compiled.

To reduce the size of the binary and to reduce the attack surface, you can choose the list of extensions to build using the PHP_EXTENSIONS Docker ARG.

For instance, run the following command to only build the opcache extension:

docker buildx bake --load --set static-builder.args.PHP_EXTENSIONS=opcache,pdo_sqlite static-builder
# ...

See the list of supported extensions.

To add libraries enabling additional functionality to the extensions you've enabled, you can pass use the PHP_EXTENSION_LIBS Docker ARG:

docker buildx bake \
  --load \
  --set static-builder.args.PHP_EXTENSIONS=gd \
  --set static-builder.args.PHP_EXTENSION_LIBS=libjpeg,libwebp \
  static-builder

GitHub Token

If you hit the GitHub API rate limit, set a GitHub Personal Access Token in an environment variable named GITHUB_TOKEN:

GITHUB_TOKEN="xxx" docker --load buildx bake static-builder
# ...

macOS

Run the following script to create a static binary for macOS (you must have Homebrew installed):

git clone https://github.com/dunglas/frankenphp
cd frankenphp
./build-static.sh

Note: this script also works on Linux (and probably on other Unixes), and is used internally by the Docker based static builder we provide.

See the list of supported extensions.