tinywan / webman-staticphp
StaticPHP 3.0 single-file binary builder and packager plugin for Webman
Requires
- php: >=8.1
- symfony/console: ^5.4 || ^6.0 || ^7.0 || ^8.0
- symfony/process: ^5.4 || ^6.0 || ^7.0 || ^8.0
- webman/console: ^1.0 || ^2.0
- workerman/webman-framework: ^1.5.4 || ^2.0 || dev-master
Requires (Dev)
- carthage-software/mago: ^1.5
- pestphp/pest: ^2.36 || ^3.0 || ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Webman StaticPHP Build Plugin
Package Webman applications into zero-dependency, single-file executables powered by StaticPHP 3.0
π Introduction
tinywan/webman-staticphp is a StaticPHP 3.0 build and packaging plugin designed for Webman. It automates webman build:phar, manages pinned spc binaries, downloads SHA-256 verified official prebuilt micro.sfx runtimes (or builds custom PHP 8.1β8.6 runtimes via craft.yml), and combines everything into a single self-contained executable with a build-manifest.json.
In default prebuilt mode, no Visual Studio C++, GCC, or Docker is required β you can even cross-package a Linux x86_64 or aarch64 production binary directly from Windows or macOS in seconds.
π Quick Start
1. Install Plugin
Run the following command in your Webman project root:
composer require tinywan/webman-staticphp --dev
2. Environment Check
Check host PHP, pinned spc binary, and cached micro.sfx availability:
php webman staticphp:doctor
3. Build & Package
# Default prebuilt mode: auto-downloads spc + official prebuilt micro.sfx (zero C++ compiler, zero Docker) php webman staticphp:package # Cross-package a Linux x86_64 production binary right from Windows or macOS php webman staticphp:package --target=linux-x86_64 --prebuilt=common --output=build/webman-linux-x86_64 # Cross-package a Linux ARM64 binary with full bulk extensions (56 extensions) php webman staticphp:package --target=linux-aarch64 --prebuilt=bulk --output=build/webman-linux-arm64 # Custom compile mode: build PHP + custom extensions from craft.yml via `spc craft` php webman staticphp:init php webman staticphp:package --craft
4. Run Artifacts
Copy the generated single-file executable to a target server (no PHP installation required) and run:
# Linux / macOS
chmod +x ./webman-linux-x86_64
./webman-linux-x86_64 start -d
./webman-linux-x86_64 status
./webman-linux-x86_64 stop
# Windows .\webman-app.exe start
π¦ Artifact Contract
Depending on the packaging mode, webman-staticphp produces a self-contained single executable plus a build manifest:
Mode 1: Prebuilt Cross-Platform Packaging (php webman staticphp:package)
Downloads official StaticPHP 3.0 prebuilt micro.sfx (verified by .sha256 and cached locally under runtime/staticphp/prebuilt/), packages webman.phar, and combines them into one standalone binary:
build/
βββ webman-app # Standalone single-file executable (webman-app.exe on Windows, ~14β18MB)
βββ webman.phar # Intermediate Webman Phar archive
βββ build-manifest.json # Target platform, SHA-256, size, PHP version, and embedded php.ini
Key Highlights
- Zero Compiler & Zero Docker: No Visual Studio C++, GCC, Xcode, or Docker required on the host machine.
- 10-Second Cross-Packaging: Build Linux
x86_64/aarch64, macOS, or Windows binaries from any OS. - Rich Official Presets:
common(37 extensions),bulk(56 extensions),gnu-bulk,minimal,spc-max(Windows 50 extensions),spc-min.
Minimal Containerization Example (Optional)
FROM alpine:latest WORKDIR /app COPY build/webman-linux-x86_64 /app/webman-app RUN chmod +x /app/webman-app EXPOSE 8787 CMD ["./webman-app", "start"]
Mode 2: Custom craft.yml Build (php webman staticphp:package --craft)
Compiles a tailored PHP 8.1β8.6 runtime with your exact extension list using StaticPHP 3.0 spc craft (supports native toolchains and Zig cross-compilation), then combines it with webman.phar:
runtime/staticphp/
βββ spc / spc.exe # Pinned StaticPHP 3.0 binary
βββ craft.yml # Declarative PHP version, extensions, SAPI, and parallel download config
βββ buildroot/bin/
βββ php / php.exe # Custom compiled static PHP CLI
βββ micro.sfx # Custom compiled phpmicro runtime
Key Highlights
- Exact Extension Control: Compile only the extensions your project needs (including PHP 8.6 support).
- Cross-Platform Safe: Automatically strips Unix-only extensions (
pcntl,posix,event, etc.) when generatingcraft.ymlon Windows. - Reproducible Builds: Commit
craft.ymlor generate CI workflows withphp webman staticphp:init-ci.
π οΈ Commands
| Command | Description |
|---|---|
php webman staticphp:package |
Package Webman into a single binary using prebuilt micro.sfx (or local micro.sfx) |
php webman staticphp:package --target=linux-x86_64 |
Cross-package a Linux x86_64 single binary from any OS |
php webman staticphp:package --prebuilt=bulk |
Select a specific official prebuilt extension preset (common, bulk, spc-max, etc.) |
php webman staticphp:package --craft |
Compile custom micro.sfx from craft.yml before packaging |
php webman staticphp:package --skip-phar |
Reuse existing build/webman.phar and only run micro:combine |
php webman staticphp:package --output=... -I ... |
Customize output path and embed extra php.ini directives |
php webman staticphp:doctor |
Check PHP, spc binary (--download, --auto-fix), and micro.sfx status |
php webman staticphp:init |
Generate Webman-tailored craft.yml (--php-version, --extensions, --parallel, --force) |
php webman staticphp:init-ci |
Generate GitHub Actions workflow (.github/workflows/staticphp-build.yml) |
βοΈ Configuration
After installing the plugin, the configuration file is located at config/plugin/tinywan/staticphp/app.php:
return [ 'enable' => true, 'spc' => [ 'version' => '3.0.0', 'work_dir' => 'runtime/staticphp', 'binary' => '', 'download_base_url' => 'https://dl.static-php.dev/v3/spc-bin', 'parallel' => 10, ], 'prebuilt' => [ 'base_url' => 'https://dl.static-php.dev/v3/php-bin', 'preset' => 'auto', 'target' => 'auto', ], 'craft' => [ 'php_version' => '8.5', 'sapi' => ['cli', 'micro'], 'extensions' => ['bcmath', 'ctype', 'curl', 'event', 'mbstring', 'opcache', 'openssl', 'pcntl', 'pdo', 'pdo_mysql', 'phar', 'posix', 'redis', 'sockets', 'zlib'], 'windows_extensions' => ['bcmath', 'ctype', 'filter', 'mbstring', 'phar', 'session', 'tokenizer', 'zlib'], ], 'build' => [ 'output_dir' => 'build', 'output_name' => 'webman-app', 'phar_path' => 'build/webman.phar', 'custom_ini' => [ 'memory_limit=256M', ], 'micro_sfx' => '', ], ];
CLI options (--spc-bin, --target, --prebuilt, --php-version, --output, -I) always take precedence over app.php.
π― Scope & Boundaries
- Supported host PHP:
>= 8.1(Webman^1.5.4/^2.0). - Supported target platforms:
linux-x86_64,linux-aarch64,macos-aarch64,macos-x86_64,windows-x64. - Windows runtime note: Workerman/Webman on Windows runs in single-process foreground mode (
pcntl/posixare Unix-only). For multi-process production deployments (start -d), targetlinux-x86_64orlinux-aarch64.
π§ͺ Quality & Testing
Tests are written with Pest, formatted, linted, and analyzed with Mago:
composer format:check
composer format
composer lint
composer analyse
composer test
composer check
πΊοΈ Documentation & References
- StaticPHP 3.0 Official Documentation
- StaticPHP GitHub Repository
- Webman Documentation
- Issue Tracker
- Tinywan
License
MIT Β© Tinywan