2021-05-07 16:58:40 +08:00
2021-04-26 16:15:06 +08:00
2021-05-07 10:20:25 +08:00
2021-05-07 16:58:40 +08:00

static-php-cli

Compile A Statically Linked PHP With Swoole and other Extensions. English README

编译纯静态的 PHP Binary 二进制文件带有各种扩展CLI 模式,暂不支持 CGI 和 FPM 模式)

版本

环境需求

  • 目前在 x86_64 和 aarch64(arm64) 架构上编译成功,其他架构需自行测试
  • 需要 Alpine Linux测试环境为 3.13 版本,其他版本未测试)系统(也就是说需要 musl
  • WSL2 也是支持的
  • 脚本支持编译的 PHP 版本 >= 7.2

开始

可以直接在旁边的 Release 中下载编译好的二进制,也可以自己编译。

# 自己编译
./static-compile-php.sh
# 完事后在 `php-dist/bin/php` 这个二进制文件可以随意拿着去任何一个 Linux 系统运行了!

# 多 PHP 版本一键编译
./multi-version-compile.sh
# 结束后多个 PHP 版本的二进制文件会在 build/ 目录下。

主分支版本

  • php: 7.4.18
  • libxml2: 2.9.10
  • curl: 7.76.1

包含扩展

  • bcmath
  • calendar
  • ctype
  • filter
  • openssl
  • pcntl
  • iconv
  • inotify (3.0.0)
  • json
  • mbstring
  • phar
  • curl
  • pdo
  • gd
  • pdo_mysql
  • mysqlnd
  • sockets
  • swoole (4.6.6)
  • redis (5.3.4)
  • simplexml
  • dom
  • xml
  • xmlwriter
  • xmlreader
  • posix
  • tokenizer

运行示例

编译后的状态 image

在不同系统直接运行 Swoft image

Todo List

  • curl/libcurl 扩展静态编译
  • 可自行选择不需要编译进入的扩展
  • php.ini 内嵌或分发
  • 尝试带进去个 composer其实自己下完全可以
  • i18n国际化脚本本身和 README

参考资料

Description
Build single static PHP binary in linux, build with PHP project together, with Swoole and other popular extensions included.
Readme MIT 42 MiB
Languages
PHP 95.8%
Shell 2%
JavaScript 1%
PowerShell 0.5%
C 0.4%
Other 0.3%