Volver al ranking

crazywhalecc/static-php-cli

PHPstatic-php.dev

Build standalone portable PHP binaries on Linux, macOS, Windows, with PHP project together, with popular extensions included.

swoolephpphp-srcphp-clistatic-link-binaryalpineworkermanstaticbinaryphp8frankenphp
Crecimiento de estrellas
Estrellas
1.9k
Forks
395
Crecimiento semanal
Issues
28
5001k1.5k
abr 2021ene 2023oct 2024jul 2026
ArtefactosPackagistcomposer require crazywhalecc/static-php-cli
README

StaticPHP

Chinese readme English readme Releases CI License Discord

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

  • :elephant: Support multiple PHP versions - PHP 8.1, 8.2, 8.3, 8.4, 8.5
  • :handbag: Build single-file PHP executable with zero dependencies
  • :hamburger: Build phpmicro self-extracting executables (combines PHP binary and source code into one file)
  • :pill: Automatic build environment checker with auto-fix capabilities
  • :zap: Linux, macOS, Windows support
  • :wrench: Easy to extend with vendor mode and custom registries
  • :books: Intelligent dependency management
  • 📦 Self-contained spc executable for easy self-installation
  • :fire: Support 100+ popular PHP extensions
  • :floppy_disk: UPX compression support (reduces binary size by 30-50%)

Single-file standalone php-cli:

out1

Combine PHP code with PHP interpreter using phpmicro:

out2

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.

  1. Fork this repository.
  2. Go to the Actions of the project and select CI.
  3. 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)
  4. 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/.

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:

Beyond Code Logo

NativePHP Logo

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.

Repositorios relacionados
swoole/swoole-src

🚀 Coroutine-based concurrency library for PHP

C++Apache License 2.0swoolecoroutines
swoole.com
18.9k3.1k
hyperf/hyperf

🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.

PHPPackagistMIT Licenseswoolecoroutine
hyperf.io
6.9k1.3k
swoft-cloud/swoft

🚀 PHP Microservice Full Coroutine Framework

PHPPackagistApache License 2.0swoolecoroutine
swoft.org
5.5k765
easy-swoole/easyswoole

swoole,easyswoole,swoole framework

PHPPackagistApache License 2.0swooleeasyswoole
easyswoole.com
4.8k503
swooletw/laravel-swoole

High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.

PHPPackagistMIT Licenseswooleswoole-server
4k383
laravel/octane

Supercharge your Laravel application's performance.

PHPPackagistMIT Licenselaraveloctane
laravel.com/docs/octane
4k342
hhxsv5/laravel-s

LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.

PHPPackagistMIT Licenseswoolelaravel
3.9k465
colinlet/PHP-Interview-QA

系统性的 PHP 技术面试问答大全(面经)。涵盖 PHP8、MySQL、Redis、Nginx、系统设计、算法、Laravel 源码及高并发架构原理,助你斩获后端研发 Offer。PHP Interview Questions & Answers.

TypeScriptnpmApache License 2.0algorithmarchitecture
colinlet.github.io/PHP-Interview-QA/
3k563
viest/php-ext-xlswriter

🚀 PHP Extension for creating and reader XLSX files.

CBSD 2-Clause "Simplified" Licensephpexcel
xlswriter.viest.me
2.4k236
viest/php-ext-xlsxwriter

🚀 PHP Extension for creating and reader XLSX files.

CBSD 2-Clause "Simplified" Licensephpexcel
xlswriter.viest.me
2.3k234
Tencent/tsf

coroutine and Swoole based php server framework in tencent

PHPPackagistOtherphpswoole
2.1k474
mix-php/mix

☄️ PHP CLI mode development framework, supports Swoole, WorkerMan, FPM, CLI-Server / PHP 命令行模式开发框架,支持 Swoole、Swow、WorkerMan、FPM、CLI-Server

PHPPackagistApache License 2.0swoolecoroutine
1.9k213