Skip to content

Commit 3816b94

Browse files
committed
Update README.md
1 parent 79d0cd4 commit 3816b94

2 files changed

Lines changed: 181 additions & 226 deletions

File tree

README-zh.md

Lines changed: 150 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,150 @@
1-
# StaticPHP
2-
3-
[![English readme](https://img.shields.io/badge/README-English%20%F0%9F%87%AC%F0%9F%87%A7-moccasin?style=flat-square)](README.md)
4-
[![Chinese readme](https://img.shields.io/badge/README-%E4%B8%AD%E6%96%87%20%F0%9F%87%A8%F0%9F%87%B3-moccasin?style=flat-square)](README-zh.md)
5-
[![Releases](https://img.shields.io/packagist/v/crazywhalecc/static-php-cli?include_prereleases&label=Release&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/releases)
6-
[![CI](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/tests.yml?branch=main&label=Build%20Test&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
7-
[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)
8-
9-
**StaticPHP** 是一个用于构建静态编译可执行文件(包括 PHP、扩展等)的强大工具。
10-
11-
## 特性
12-
13-
- :elephant: **支持多 PHP 版本** - 支持 PHP 8.1, 8.2, 8.3, 8.4, 8.5
14-
- :handbag: **单文件 PHP 可执行文件** - 构建零依赖的独立 PHP
15-
- :hamburger: **phpmicro 集成** - 构建 **[phpmicro](https://github.com/dixyes/phpmicro)** 自解压可执行文件(将 PHP 二进制文件和源代码合并为一个文件)
16-
- :pill: **智能环境检查器** - 自动构建环境检查器,具备自动修复功能
17-
- :zap: **跨平台支持** - 支持 Linux、macOS、FreeBSD 和 Windows
18-
- :wrench: **可配置补丁** - 可自定义的源代码补丁系统
19-
- :books: **智能依赖管理** - 自动处理构建依赖
20-
- 📦 **自包含工具** - 提供使用 [box](https://github.com/box-project/box) 构建的 `spc` 可执行文件
21-
- :fire: **广泛的扩展支持** - 支持 75+ 流行 [扩展](https://static-php.dev/zh/guide/extensions.html)
22-
- :floppy_disk: **UPX 压缩** - 减小二进制文件大小 30-50%(仅 Linux/Windows)
23-
24-
**单文件独立 php-cli:**
25-
26-
<img width="700" alt="out1" src="https://github.com/crazywhalecc/static-php-cli/assets/20330940/01a2e60f-13b0-4242-a645-f7afa4936396">
27-
28-
**使用 phpmicro 将 PHP 代码与 PHP 解释器结合:**
29-
30-
<img width="700" alt="out2" src="https://github.com/crazywhalecc/static-php-cli/assets/20330940/46b7128d-fb72-4169-957e-48564c3ff3e2">
31-
32-
## 快速开始
33-
34-
### 1. 下载 spc 二进制文件
35-
36-
```bash
37-
# Linux x86_64
38-
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-x86_64
39-
# Linux aarch64
40-
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-aarch64
41-
# macOS x86_64 (Intel)
42-
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-x86_64
43-
# macOS aarch64 (Apple)
44-
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-aarch64
45-
# Windows (x86_64, win10 build 17063 或更高版本,请先安装 VS2022)
46-
curl.exe -fsSL -o spc.exe https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe
47-
```
48-
49-
对于 macOS 和 Linux,请先添加执行权限:
50-
51-
```bash
52-
chmod +x ./spc
53-
```
54-
55-
### 2. 构建静态 PHP
56-
57-
首先,创建一个 `craft.yml` 文件,并从 [扩展列表](https://static-php.dev/zh/guide/extensions.html)[命令生成器](https://static-php.dev/zh/guide/cli-generator.html) 中指定要包含的扩展:
58-
59-
```yml
60-
# PHP 版本支持:8.1, 8.2, 8.3, 8.4, 8.5
61-
php-version: 8.4
62-
# 在此处放置您的扩展列表
63-
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"
64-
sapi:
65-
- cli
66-
- micro
67-
- fpm
68-
download-options:
69-
prefer-pre-built: true
70-
```
71-
72-
运行命令:
73-
74-
```bash
75-
./spc craft
76-
77-
# 输出完整控制台日志
78-
./spc craft --debug
79-
```
80-
81-
### 3. 静态 PHP 使用
82-
83-
现在您可以将 StaticPHP 构建的二进制文件复制到另一台机器上,无需依赖即可运行:
84-
85-
```
86-
# php-cli
87-
buildroot/bin/php -v
88-
89-
# phpmicro
90-
echo '<?php echo "Hello world!\n";' > a.php
91-
./spc micro:combine a.php -O my-app
92-
./my-app
93-
94-
# php-fpm
95-
buildroot/bin/php-fpm -v
96-
```
97-
98-
## 文档
99-
100-
当前 README 包含基本用法。有关 StaticPHP 的所有功能,
101-
请访问 <https://static-php.dev>
102-
103-
## 直接下载
104-
105-
如果您不想构建或想先测试,可以从 [Actions](https://github.com/static-php/static-php-cli-hosted/actions/workflows/build-php-bulk.yml) 下载示例预编译工件,或从自托管服务器下载。
106-
107-
以下是几个具有不同扩展组合的预编译静态 PHP 二进制文件,
108-
您可以根据需要直接下载。
109-
110-
| 组合名称 | 扩展数量 | 系统 | 备注 |
111-
|----------------------------------------------------------------------|----------------------------------------------------------------------------|--------------|--------------------|
112-
| [common](https://dl.static-php.dev/static-php-cli/common/) | [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) | Linux, macOS | 二进制文件大小约为 7.5MB |
113-
| [bulk](https://dl.static-php.dev/static-php-cli/bulk/) | [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) | Linux, macOS | 二进制文件大小约为 25MB |
114-
| [gnu-bulk](https://dl.static-php.dev/static-php-cli/gnu-bulk/) | [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) | Linux, macOS | 使用 glibc 的 bulk 组合 |
115-
| [minimal](https://dl.static-php.dev/static-php-cli/minimal/) | [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) | Linux, macOS | 二进制文件大小约为 3MB |
116-
| [spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/) | [5](https://dl.static-php.dev/static-php-cli/windows/spc-min/README.txt) | Windows | 二进制文件大小约为 3MB |
117-
| [spc-max](https://dl.static-php.dev/static-php-cli/windows/spc-max/) | [40+](https://dl.static-php.dev/static-php-cli/windows/spc-max/README.txt) | Windows | 二进制文件大小约为 8.5MB |
118-
119-
> Linux 和 Windows 支持对二进制文件进行 UPX 压缩,可以将二进制文件大小减少 30% 到 50%。
120-
> macOS 不支持 UPX 压缩,因此 mac 的预构建二进制文件大小较大。
121-
122-
### 在线构建(使用 GitHub Actions)
123-
124-
上方直接下载的二进制不能满足需求时,可使用 GitHub Action 可以轻松构建静态编译的 PHP,
125-
同时自行定义要编译的扩展。
126-
127-
1. Fork 本项目。
128-
2. 进入项目的 Actions 并选择 `CI`
129-
3. 选择 `Run workflow`,填入您要编译的 PHP 版本、目标类型和扩展列表。(扩展用逗号分隔,例如 `bcmath,curl,mbstring`
130-
4. 等待一段时间后,进入相应的任务并获取 `Artifacts`
131-
132-
如果您启用 `debug`,构建时将输出所有日志,包括编译日志,以便故障排除。
133-
134-
## 贡献
135-
136-
如果您需要的扩展缺失,可以创建 issue。
137-
如果您熟悉本项目,也欢迎发起 pull request。
138-
139-
如果您想贡献文档,请直接编辑 `docs/` 目录。
140-
141-
现在有一个 [static-php](https://github.com/static-php) 组织,用于存储与项目相关的仓库。
142-
143-
## 赞助本项目
144-
145-
您可以从 [GitHub Sponsor](https://github.com/crazywhalecc) 赞助我或我的项目。您捐赠的一部分将用于维护 **static-php.dev** 服务器。
146-
147-
**特别感谢以下赞助商**
148-
149-
<a href="https://beyondco.de/"><img src="/docs/public/images/beyondcode-seeklogo.png" width="300" alt="Beyond Code Logo" /></a>
150-
151-
<a href="https://nativephp.com/"><img src="/docs/public/images/nativephp-logo.svg" width="300" alt="NativePHP Logo" /></a>
152-
153-
## 开源许可证
154-
155-
本项目本身基于 MIT 许可证,
156-
一些新添加的扩展和依赖可能来自其他项目,
157-
这些代码文件的头部也会给出额外的许可证和作者说明。
158-
159-
这些是类似的项目:
160-
161-
- [dixyes/lwmbs](https://github.com/dixyes/lwmbs)
162-
- [swoole/swoole-cli](https://github.com/swoole/swoole-cli)
163-
164-
本项目使用了 [dixyes/lwmbs](https://github.com/dixyes/lwmbs) 的一些代码,例如 Windows 静态构建目标和 libiconv 支持。
165-
lwmbs 基于 [Mulan PSL 2](http://license.coscl.org.cn/MulanPSL2) 许可证。
166-
167-
由于本项目的特殊性,
168-
项目编译过程中会使用许多其他开源项目,如 curl 和 protobuf,
169-
它们都有自己的开源许可证。
170-
171-
请在编译后使用 `bin/spc dump-license` 命令导出项目中使用的开源许可证,
172-
并遵守相应项目的 LICENSE。
1+
# StaticPHP
2+
3+
[![Chinese readme](https://img.shields.io/badge/README-%E4%B8%AD%E6%96%87%20%F0%9F%87%A8%F0%9F%87%B3-moccasin?style=flat-square)](README-zh.md)
4+
[![English readme](https://img.shields.io/badge/README-English%20%F0%9F%87%AC%F0%9F%87%A7-moccasin?style=flat-square)](README.md)
5+
[![Releases](https://img.shields.io/packagist/v/crazywhalecc/static-php-cli?include_prereleases&label=Release&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/releases)
6+
[![CI](https://img.shields.io/github/actions/workflow/status/crazywhalecc/static-php-cli/tests.yml?branch=main&label=Build%20Test&style=flat-square)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
7+
[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)
8+
9+
**StaticPHP** 是一个强大的工具,用于构建可移植的可执行文件,包括 PHP、扩展等。
10+
11+
## 特性
12+
13+
- :elephant: 支持多个 PHP 版本 - PHP 8.1, 8.2, 8.3, 8.4, 8.5
14+
- :handbag: 构建零依赖的单文件 PHP 可执行程序
15+
- :hamburger: 构建 **[phpmicro](https://github.com/static-php/phpmicro)** 自解压可执行文件(将 PHP 二进制和源码合并为单个文件)
16+
- :pill: 自动构建环境检查器,支持自动修复
17+
- :zap: 支持 `Linux``macOS``Windows`
18+
- :wrench: 通过 vendor 模式和自定义注册表实现便捷扩展
19+
- :books: 智能依赖管理
20+
- 📦 自包含 `spc` 可执行文件,便于自安装
21+
- :fire: 支持 100+ 热门 [PHP 扩展](https://static-php.dev/en/guide/extensions.html)
22+
- :floppy_disk: 支持 UPX 压缩(二进制体积可缩小 30-50%)
23+
24+
**单文件独立 php-cli:**
25+
26+
<img width="700" alt="out1" src="https://github.com/crazywhalecc/static-php-cli/assets/20330940/01a2e60f-13b0-4242-a645-f7afa4936396">
27+
28+
**使用 phpmicro 将 PHP 代码与 PHP 解释器结合:**
29+
30+
<img width="700" alt="out2" src="https://github.com/crazywhalecc/static-php-cli/assets/20330940/46b7128d-fb72-4169-957e-48564c3ff3e2">
31+
32+
## 快速开始
33+
34+
### 1. 下载 spc 二进制
35+
36+
```bash
37+
# For Linux x86_64
38+
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-release/latest/spc-linux-x86_64
39+
# For Linux aarch64
40+
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-release/latest/spc-linux-aarch64
41+
# macOS x86_64 (Intel)
42+
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-release/latest/spc-macos-x86_64
43+
# macOS aarch64 (Apple)
44+
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-release/latest/spc-macos-aarch64
45+
# Windows (x86_64, win10 build 17063 or later, please install VS2022 first)
46+
curl.exe -fsSL -o spc.exe https://dl.static-php.dev/v3/spc-release/latest/spc-windows-x64.exe
47+
```
48+
49+
对于 macOS 和 Linux,请先添加可执行权限:
50+
51+
```bash
52+
chmod +x ./spc
53+
```
54+
55+
### 2. 构建静态 PHP
56+
57+
首先,创建 `craft.yml` 文件,并从 [扩展列表](https://static-php.dev/en/guide/extensions.html)[命令生成器](https://static-php.dev/en/guide/cli-generator.html) 指定要包含的扩展:
58+
59+
```yml
60+
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5
61+
php-version: 8.5
62+
# Put your extension list here
63+
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"
64+
sapi:
65+
- cli
66+
- micro
67+
download-options:
68+
parallel: 10
69+
```
70+
71+
运行命令:
72+
73+
```bash
74+
./spc craft
75+
76+
# 输出完整控制台日志
77+
./spc craft -vvv
78+
```
79+
80+
### 3. 静态 PHP 使用
81+
82+
现在你可以将 StaticPHP 构建的二进制复制到另一台机器并在无依赖环境下运行:
83+
84+
```
85+
# php-cli
86+
buildroot/bin/php -v
87+
88+
# phpmicro
89+
echo '<?php echo "Hello world!\n";' > a.php
90+
./spc micro:combine a.php -O my-app
91+
./my-app
92+
```
93+
94+
## 文档
95+
96+
当前 README 包含基础用法。有关 StaticPHP 的完整功能集,
97+
请访问 <https://static-php.dev>
98+
99+
## 直接下载
100+
101+
如果你暂时不想构建,或只想先测试,可以从 [Actions](https://github.com/static-php/static-php-cli-hosted/actions/workflows/build-php-bulk.yml) 下载示例预编译产物,或从自托管服务器下载。
102+
103+
我们为每个 PHP 版本提供 2 种扩展集合:
104+
105+
- **gigantic**:尽可能包含更多扩展,二进制大小约 100-150MB。
106+
- **base**:仅包含 StaticPHP 自身使用的少量扩展,二进制大小约 10MB。
107+
108+
> WIP
109+
110+
### 在线构建(使用 GitHub Actions)
111+
112+
当上方直接下载的二进制无法满足你的需求时,
113+
你可以使用 GitHub Actions 轻松构建静态编译的 PHP,
114+
并同时自定义要编译的扩展列表。
115+
116+
1. Fork 此仓库。
117+
2. 进入项目的 Actions 并选择 `CI`
118+
3. 选择 `Run workflow`,填写你要编译的 PHP 版本、目标类型和扩展列表。(扩展用逗号分隔,例如 `bcmath,curl,mbstring`
119+
4. 等待工作流执行完成后,进入对应运行记录并下载 `Artifacts`
120+
121+
如果你启用 `debug`,构建时将输出所有日志,包括编译日志,便于排查问题。
122+
123+
> 我们也计划在未来提供可复用的 GitHub Actions 工作流,
124+
> 这样你无需 fork 本项目,也能在自己的仓库中轻松构建 static PHP。
125+
126+
## 贡献
127+
128+
如果你需要的扩展缺失,可以创建 issue。
129+
如果你熟悉本项目,也欢迎发起 pull request。
130+
131+
如果你想贡献文档,请直接编辑 `docs/`
132+
133+
## 赞助本项目
134+
135+
你可以通过 [GitHub Sponsor](https://github.com/crazywhalecc) 赞助我或我的项目。你捐赠的一部分将用于维护 **static-php.dev** 服务器。
136+
137+
**特别感谢以下赞助商:**
138+
139+
<a href="https://beyondco.de/"><img src="/docs/public/images/beyondcode-seeklogo.png" width="300" alt="Beyond Code Logo" /></a>
140+
141+
<a href="https://nativephp.com/"><img src="/docs/public/images/nativephp-logo.svg" width="300" alt="NativePHP Logo" /></a>
142+
143+
## 开源许可证
144+
145+
本项目本身采用 MIT 许可证。
146+
一些新添加的扩展和依赖可能来自其他项目。
147+
这些源码文件头部也可能包含额外的 LICENSE 和 AUTHOR 信息。
148+
149+
请在编译后使用 `bin/spc dump-license` 命令导出项目中使用的开源许可证,
150+
并遵守对应项目的 LICENSE。

0 commit comments

Comments
 (0)