Search by

tinywan / webman-staticphp

Tinywan

StaticPHP 3.0 single-file binary builder and packager plugin for Webman

Package info

github.com/Tinywan/webman-staticphp

pkg:composer/tinywan/webman-staticphp

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-12-01 01:33 UTC

This package is auto-updated.

Last update: 2026-12-01 01:41:55 UTC


README

Webman StaticPHP Build Plugin

Package Webman applications into zero-dependency, single-file executables powered by StaticPHP 3.0

PHP Version Webman Plugin StaticPHP 3.0 Cross Platform MIT License

English | δΈ­ζ–‡

πŸ“– 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 generating craft.yml on Windows.
  • Reproducible Builds: Commit craft.yml or generate CI workflows with php 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/posix are Unix-only). For multi-process production deployments (start -d), target linux-x86_64 or linux-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

License

MIT Β© Tinywan