crazywhalecc / static-php-cli
Build single static PHP binary, with PHP project together, with popular extensions included.
Fund package maintenance!
Requires
- php: >= 8.3
- ext-mbstring: *
- ext-zlib: *
- laravel/prompts: ^0.1.12
- symfony/console: ^5.4 || ^6 || ^7
- symfony/process: ^7.2
- symfony/yaml: ^7.2
- zhamao/logger: ^1.1.3
Requires (Dev)
- captainhook/captainhook-phar: ^5.23
- captainhook/hook-installer: ^1.0
- friendsofphp/php-cs-fixer: ^3.60
- humbug/box: ^4.5.0 || ^4.6.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.3 || ^9.5
- v3.x-dev
- 2.8.5
- 2.8.4
- 2.8.3
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.11
- 2.7.10
- 2.7.9
- 2.7.8
- 2.7.7
- 2.7.6
- 2.7.5
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.1.0-beta.4
- 2.1.0-beta.3
- 2.1.0-beta.2
- 2.0.1
- 2.0.0
- 2.0-rc9
- 2.0-rc8
- 2.0-rc7
- 2.0-rc6
- 2.0-rc5
- 2.0-rc4
- 2.0-rc3
- 2.0-rc2
- 2.0-rc1
- 2.0.0-beta2
- dev-feat/pgo-v3
- dev-feat/pgo
- dev-v3c/ext-fastchart-fastjson
- dev-v3c/llvm-tools
- dev-v3c/package-builder-toolchain-strip
- dev-v3c/linux-musl-check-setenv
- dev-v3c/artifact-static-helpers
- dev-v3c/deduplicate-flags-paired
- dev-v3c/avx512-patch-rename
- dev-v3c/library-fixes
- dev-v3c/xlswriter-gnu17
- dev-v3c/toolchain-default-ranlib
- dev-v3c/artifact-pkg-root-path-template
- dev-v3c/watcher-drop-ldflags
- dev-v3c/imagemagick-without-gcc-arch
- dev-fix/xlswriter
- dev-v3-check/4
- dev-v3-check/3
- dev-v3-check/2
- dev-revert-1153-fix/heif
- dev-main
- dev-fix/heif
- dev-crazywhalecc-patch-1
- dev-revert-1086-fix/xlswriter-macos-kr-declaration
- dev-ttt
- dev-fix/zlib
- dev-fix/protobuf
- dev-shared
- dev-feat/avif-dec
- dev-feat/xcaddy-plugins
- dev-release-oss
- dev-fix/postgresql-gnu-aarch64
- dev-henderkes-patch-1
- dev-feat/updating-sources
- dev-v3-feat/tests
- dev-docs/ga
- dev-vcpkg
- dev-pmmp-experiment
This package is auto-updated.
Last update: 2026-05-26 00:51:42 UTC
README
StaticPHP is a powerful tool designed for building portable executables including PHP, extensions, and more.
Important
We are preparing to release v3, which will include a project rename from static-php-cli to StaticPHP. And this branch is for v3. For v2, please check the v2 branch. Please update your references and stay tuned for the official release.
Features
- 🐘 Support multiple PHP versions - PHP 8.1, 8.2, 8.3, 8.4, 8.5
- 👜 Build single-file PHP executable with zero dependencies
- 🍔 Build phpmicro self-extracting executables (combines PHP binary and source code into one file)
- 💊 Automatic build environment checker with auto-fix capabilities
- ⚡
Linux,macOS,Windowssupport - 🔧 Easy to extend with vendor mode and custom registries
- 📚 Intelligent dependency management
- 📦 Self-contained
spcexecutable for easy self-installation - 🔥 Support 100+ popular PHP extensions
- 💾 UPX compression support (reduces binary size by 30-50%)
Single-file standalone php-cli:
Combine PHP code with PHP interpreter using phpmicro:
Quickstart
1. Download spc binary
# For Linux x86_64 curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-x86_64 # For Linux aarch64 curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-aarch64 # macOS x86_64 (Intel) curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-x86_64 # macOS aarch64 (Apple) curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-aarch64 # Windows (x86_64, win10 build 17063 or later, please install VS2022 first) curl.exe -fsSL -o spc.exe https://dl.static-php.dev/v3/spc-bin/nightly/spc-windows-x64.exe
For macOS and Linux, add execute permission first:
chmod +x ./spc
2. Build Static PHP
First, create a craft.yml file and specify which extensions you want to include from extension list or command generator:
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5 php-version: 8.5 # Put your extension list here extensions: "apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,gd,iconv,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,simplexml,sockets,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib" sapi: - cli - micro download-options: parallel: 10
Run command:
./spc craft
# Output full console log
./spc craft -vvv
3. Static PHP usage
Now you can copy binaries built by StaticPHP to another machine and run with no dependencies:
# php-cli
buildroot/bin/php -v
# phpmicro
echo '<?php echo "Hello world!\n";' > a.php
./spc micro:combine a.php -O my-app
./my-app
Documentation
The current README contains basic usage. For the complete feature set of StaticPHP, see https://static-php.dev.
Direct Download
If you do not want to build yet or just want to test first, you can download example pre-compiled artifacts from Actions or from a self-hosted server.
We offer 2 types of extension sets for each PHP version:
- gigantic: Includes as many extensions as possible, the binary size is about 100-150MB.
- base: Only includes a few extensions used by StaticPHP itself, the binary size is about 10MB.
WIP
Build Online (using GitHub Actions)
When the direct-download binaries above cannot meet your needs, you can use GitHub Actions to easily build a statically compiled PHP while defining your own extension list.
- Fork this repository.
- Go to the Actions of the project and select
CI. - Select
Run workflow, fill in the PHP version you want to compile, the target type, and the list of extensions. (extensions comma separated, e.g.bcmath,curl,mbstring) - After waiting for the workflow to finish, open the corresponding run and download
Artifacts.
If you enable debug, all logs will be output at build time, including compiled logs, for troubleshooting.
We are also planning to provide a reusable GitHub Actions workflow in the future, so that you can easily build static PHP in your own repository, without forking this project.
Contribution
If the extension you need is missing, you can create an issue. If you are familiar with this project, you are also welcome to initiate a pull request.
If you want to contribute documentation, please just edit in docs/.
Sponsor this project
You can sponsor me or my project from GitHub Sponsor. A portion of your donation will be used to maintain the static-php.dev server.
Special thanks to sponsors below:
Open-Source License
This project itself is licensed under MIT. Some newly added extensions and dependencies may originate from other projects. The headers of those source files may also include additional LICENSE and AUTHOR information.
Please use the bin/spc dump-license command to export the open source licenses used in the project after compilation,
and comply with the corresponding project's LICENSE.
