static-php-cli/README.md

62 lines
1.6 KiB
Markdown
Raw Normal View History

2021-04-26 16:15:06 +08:00
# static-php-swoole
Compile A Statically Linked PHP With Swoole and other Extensions
2021-04-26 16:32:26 +08:00
编译纯静态的 PHP Binary 二进制文件带有各种扩展CLI 模式,暂不支持 CGI 和 FPM 模式)
2021-04-28 00:03:14 +08:00
[![作者QQ](https://img.shields.io/badge/version-1.0.0-orange.svg)]()
2021-04-26 16:32:26 +08:00
## 环境需求
- 目前在 x86_64 平台试验成功,其他架构需自行测试
- 需要 Alpine Linux测试环境为 3.13 版本,其他版本未测试)系统(也就是说需要 musl
- WSL2 也是支持的
## 开始
2021-04-26 16:45:57 +08:00
可以直接带走此仓库中的编译好的二进制(`./php`),版本 7.4.16swoole 版本 4.6.6)。
2021-04-26 16:32:26 +08:00
```bash
2021-04-26 16:45:57 +08:00
# 自己编译
2021-04-26 16:32:26 +08:00
./static-compile-php.sh
```
完事后在 `php-dist/bin/php` 这个二进制文件可以随意拿着去任何一个 Linux 系统运行了!
## 包含扩展
- calendar
- ctype
- filter
- openssl
- pcntl
- iconv
- json
- mbstring
- phar
- pdo
2021-04-26 16:33:58 +08:00
- gd
2021-04-26 16:32:26 +08:00
- pdo_mysql
- mysqlnd
- sockets
- swoole
- redis
- simplexml
- dom
- xml
- xmlwriter
- xmlreader
- posix
- tokenizer
## 运行示例
2021-04-26 16:35:36 +08:00
编译后的状态
![image](https://user-images.githubusercontent.com/20330940/116053556-68a30800-a6ad-11eb-88f8-aba015899e43.png)
2021-04-26 16:32:26 +08:00
在不同系统直接运行 Swoft
![image](https://user-images.githubusercontent.com/20330940/116053161-f16d7400-a6ac-11eb-87b8-e510c6454861.png)
2021-04-26 20:12:30 +08:00
2021-04-28 00:01:42 +08:00
## Todo List
- [X] curl/libcurl 扩展静态编译
- [ ] 可自行选择不需要编译进入的扩展
- [ ] php.ini 内嵌或分发
- [ ] 尝试带进去个 composer其实自己下完全可以
2021-04-27 16:14:18 +08:00
## 参考资料
- <https://blog.terrywh.net/post/2019/php-static-openssl/>
- <https://stackoverflow.com/a/37245653>
- <http://blog.gaoyuan.xyz/2014/04/09/statically-compile-php/>