mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-03 14:55:39 +08:00
Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66942f866e | ||
|
|
7440fe3936 | ||
|
|
35395538b4 | ||
|
|
36f4833b71 | ||
|
|
33de213a66 | ||
|
|
9fa229fa36 | ||
|
|
6efa11d8af | ||
|
|
cc3fa7d1fd | ||
|
|
de5d92be70 | ||
|
|
cb679247fc | ||
|
|
f7e961c223 | ||
|
|
89fc7c6482 | ||
|
|
12b32ce1a0 | ||
|
|
cdf4d4999e | ||
|
|
6926a5c989 | ||
|
|
2944eb4a75 | ||
|
|
135259e0db | ||
|
|
38e2b587e1 | ||
|
|
92a0078d54 | ||
| e0c7963713 | |||
|
|
1069ae3539 | ||
| 908f7c8b98 | |||
|
|
89a1526501 | ||
|
|
6e9a975e94 | ||
|
|
b3cbf9cc37 | ||
|
|
22ac543fe7 | ||
|
|
cc3aa2ec44 | ||
|
|
609790ea7b | ||
|
|
cb98414cef | ||
|
|
85efd3275b | ||
|
|
2b3f736c68 | ||
|
|
18c74cdadb | ||
|
|
7cb7facec3 | ||
|
|
cf42a4ee71 | ||
|
|
bce1d13d91 | ||
|
|
7ad936f8c2 | ||
|
|
b46b58ad49 | ||
|
|
189dc21f1a | ||
|
|
7bf38281d5 | ||
|
|
980d25c40a | ||
|
|
e1b0013201 | ||
|
|
50e5cea9fb | ||
|
|
6b258bee6b | ||
|
|
ad76951419 | ||
|
|
862f5e9924 | ||
|
|
0a4d604069 | ||
|
|
720341316b |
103
README-en.md
Executable file
103
README-en.md
Executable file
@@ -0,0 +1,103 @@
|
||||
# static-php-cli
|
||||
Compile A Statically Linked PHP With Swoole and other Extensions.
|
||||
|
||||
BTW, It's only for CLI mode.
|
||||
|
||||
[]()
|
||||
|
||||
## Requirements
|
||||
- Tested on `x86_64` and `aarch64` platform, others have not tested.
|
||||
- Docker required (or alpine linux when I write single script file)
|
||||
- Supporting PHP version from 7.2 to 8.0
|
||||
|
||||
## Start
|
||||
You can directly download static binary in Release.
|
||||
|
||||
Here's help command to compile it yourself:
|
||||
```bash
|
||||
git clone https://github.com/crazywhalecc/static-php-cli.git
|
||||
cd static-php-cli/docker
|
||||
docker build -t static-php .
|
||||
```
|
||||
|
||||
After compilation you can use command to get static php binary file:
|
||||
```bash
|
||||
mkdir dist
|
||||
docker run --rm -v $(pwd)/dist:/dist/ -it static-php cp php-dist/bin/php /dist/
|
||||
cd dist
|
||||
file ./php
|
||||
```
|
||||
|
||||
To customize PHP extensions, edit `docker/extensions.txt` file, and rules below:
|
||||
- Use `#` as comment, to mark not install
|
||||
- extensions name uses lower case, and default file contains all supported extensions, if u need other extensions, consider write an Issue
|
||||
|
||||
## Supported PHP extensions
|
||||
| Support | PHP Ext Name | Version | Comments |
|
||||
| ------- | ------------ | ------- | ---------------------------------------- |
|
||||
| yes | bcmath | * | |
|
||||
| yes | calendar | * | |
|
||||
| yes | ctype | * | |
|
||||
| yes | curl | * | |
|
||||
| yes | dom | * | |
|
||||
| | event | | |
|
||||
| yes | filter | * | |
|
||||
| yes | gd | * | |
|
||||
| yes | hash | * | PHP7.3 or older uses `--enable-hash` |
|
||||
| yes | iconv | * | |
|
||||
| yes | inotify | 3.0.0 | |
|
||||
| yes | json | * | |
|
||||
| yes | libxml | * | |
|
||||
| yes | mbstring | * | |
|
||||
| yes | mongodb | >=1.9.1 | not tested |
|
||||
| | mysqli | | |
|
||||
| yes | mysqlnd | * | |
|
||||
| yes | openssl | * | |
|
||||
| yes | pcntl | * | |
|
||||
| yes | pdo | * | |
|
||||
| yes | pdo_mysql | * | |
|
||||
| | pdo_pgsql | * | |
|
||||
| yes | phar | * | |
|
||||
| yes | posix | * | |
|
||||
| yes | redis | * | |
|
||||
| yes | simplexml | * | |
|
||||
| yes | sockets | * | |
|
||||
| yes | sqlite3 | * | not tested |
|
||||
| yes | swoole | >=4.6.6 | support mysqlnd, sockets, openssl, redis |
|
||||
| yes | tokenizer | * | |
|
||||
| yes | xml | * | |
|
||||
| yes | xmlreader | * | |
|
||||
| yes | xmlwriter | * | |
|
||||
| | zip | | |
|
||||
| yes | zlib | * | |
|
||||
|
||||
## Customization
|
||||
- `docker/Dockerfile` edit `VER_PHP=x.x.x` to switch PHP version.
|
||||
- `docker/Dockerfile` edit `USE_BACKUP=yes` to use backup download address (download faster if you are not in mainland China).
|
||||
- `docker/extensions.txt` edit extensions.
|
||||
- `docker/compile-php.sh` file `php_compile_args` function to adjust PHP configure arguments.
|
||||
- `docker/check-extensions.sh` file `check_in_configure` function to adjust extensions' configure arguments.
|
||||
- `docker/config.json` edit extensions and dependencies version and download links.
|
||||
|
||||
## Current Issue
|
||||
- [ ] Not support event(libevent), because of its `config.m4` and code.
|
||||
- [ ] Swoole not support `--enable-swoole-curl`.
|
||||
- [ ] Not support readline, maybe caused by ncurses library.
|
||||
- [X] Not support curl (solved)
|
||||
- [X] Customize extensions to compile
|
||||
- [ ] php.ini integration
|
||||
- [X] i18n (including README and scripts)
|
||||
|
||||
## Running preview
|
||||
After-compile status
|
||||
|
||||

|
||||
|
||||
Run Workerman directly
|
||||
|
||||

|
||||
|
||||
## References
|
||||
- <https://blog.terrywh.net/post/2019/php-static-openssl/>
|
||||
- <https://stackoverflow.com/a/37245653>
|
||||
- <http://blog.gaoyuan.xyz/2014/04/09/statically-compile-php/>
|
||||
132
README.md
Normal file → Executable file
132
README.md
Normal file → Executable file
@@ -1,61 +1,105 @@
|
||||
# static-php-swoole
|
||||
Compile A Statically Linked PHP With Swoole and other Extensions
|
||||
编译纯静态的 PHP Binary 二进制文件,带有各种扩展(CLI 模式,暂不支持 CGI 和 FPM 模式)
|
||||
# static-php-cli
|
||||
Compile A Statically Linked PHP With Swoole and other Extensions. [English README](/README-en.md)
|
||||
|
||||
[]()
|
||||
编译纯静态的 PHP Binary 二进制文件,带有各种扩展,让 PHP-cli 应用变得更便携!
|
||||
|
||||
注:只能编译 CLI 模式,暂不支持 CGI 和 FPM 模式
|
||||
|
||||
[]()
|
||||
|
||||
## 环境需求
|
||||
- 目前在 x86_64 和 aarch64(arm64) 架构上编译成功,其他架构需自行测试
|
||||
- 需要 Alpine Linux(测试环境为 3.13 版本,其他版本未测试)系统(也就是说需要 musl)
|
||||
- WSL2 也是支持的
|
||||
- 需要 Docker(或等我将脚本提出来也可以直接在 Alpine Linux 上使用)
|
||||
- 脚本支持编译的 PHP 版本(7.2 ~ 8.0)
|
||||
|
||||
## 开始
|
||||
可以直接在旁边的 Release 中下载编译好的二进制,也可以自己编译。
|
||||
可以直接在旁边的 Release 中下载编译好的二进制。
|
||||
|
||||
也可以自己使用 Dockerfile 进行编译构建:
|
||||
```bash
|
||||
# 自己编译
|
||||
./static-compile-php.sh
|
||||
# 完事后在 `php-dist/bin/php` 这个二进制文件可以随意拿着去任何一个 Linux 系统运行了!
|
||||
git clone https://github.com/crazywhalecc/static-php-cli.git
|
||||
cd static-php-cli/docker
|
||||
docker build -t static-php .
|
||||
```
|
||||
|
||||
## 包含扩展
|
||||
- bcmath
|
||||
- calendar
|
||||
- ctype
|
||||
- filter
|
||||
- openssl
|
||||
- pcntl
|
||||
- iconv
|
||||
- json
|
||||
- mbstring
|
||||
- phar
|
||||
- curl
|
||||
- pdo
|
||||
- gd
|
||||
- pdo_mysql
|
||||
- mysqlnd
|
||||
- sockets
|
||||
- swoole
|
||||
- redis
|
||||
- simplexml
|
||||
- dom
|
||||
- xml
|
||||
- xmlwriter
|
||||
- xmlreader
|
||||
- posix
|
||||
- tokenizer
|
||||
编译之后可以使用下方命令将二进制 PHP 提取出来,用以下方式:
|
||||
```bash
|
||||
mkdir dist
|
||||
docker run --rm -v $(pwd)/dist:/dist/ -it static-php cp php-dist/bin/php /dist/
|
||||
cd dist
|
||||
file ./php
|
||||
```
|
||||
|
||||
如果要选择安装的扩展,可以修改 `docker/extensions.txt` 文件,具体规则如下:
|
||||
- 文件内使用 `#` 可以注释,表示不安装
|
||||
- 扩展名一律使用小写,目前默认状态下文件内所列的扩展为支持的扩展,其他扩展暂不支持,如有需求请提 Issue 添加
|
||||
|
||||
## 支持的扩展表
|
||||
| 是否支持 | PHP 扩展名称 | 支持版本 | 备注 |
|
||||
| -------- | ------------ | -------- | ------------------------------------------------------- |
|
||||
| yes | bcmath | * | |
|
||||
| yes | calendar | * | |
|
||||
| yes | ctype | * | |
|
||||
| yes | curl | * | |
|
||||
| yes | dom | * | |
|
||||
| | event | | |
|
||||
| yes | filter | * | |
|
||||
| yes | gd | * | |
|
||||
| yes | hash | * | PHP7.3及以下版本需指定 `--enable-hash`,7.4以上默认开启 |
|
||||
| yes | iconv | * | |
|
||||
| yes | inotify | 3.0.0 | |
|
||||
| yes | json | * | |
|
||||
| yes | libxml | * | |
|
||||
| yes | mbstring | * | |
|
||||
| yes | mongodb | >=1.9.1 | not tested |
|
||||
| | mysqli | | |
|
||||
| yes | mysqlnd | * | |
|
||||
| yes | openssl | * | |
|
||||
| yes | pcntl | * | |
|
||||
| yes | pdo | * | |
|
||||
| yes | pdo_mysql | * | |
|
||||
| | pdo_pgsql | * | |
|
||||
| yes | phar | * | |
|
||||
| yes | posix | * | |
|
||||
| yes | redis | * | |
|
||||
| yes | simplexml | * | |
|
||||
| yes | sockets | * | |
|
||||
| yes | sqlite3 | * | |
|
||||
| yes | swoole | >=4.6.6 | 默认支持mysqlnd, sockets, openssl, redis |
|
||||
| yes | tokenizer | * | |
|
||||
| yes | xml | * | |
|
||||
| yes | xmlreader | * | |
|
||||
| yes | xmlwriter | * | |
|
||||
| | zip | | |
|
||||
| yes | zlib | * | |
|
||||
|
||||
## 自定义
|
||||
- `docker/Dockerfile` 中修改 `VER_PHP=x.x.x` 来更换 PHP 版本。
|
||||
- `docker/Dockerfile` 中修改 `USE_BACKUP=yes` 使用备用下载源码地址(不在中国大陆可以使用备用地址)。
|
||||
- `docker/extensions.txt` 指定要编译安装的扩展。
|
||||
- `docker/compile-php.sh` 中的 `php_compile_args` 函数来调整 PHP 编译参数。
|
||||
- `docker/check-extensions.sh` 中的 `check_in_configure` 函数可调整 PHP 扩展编译的参数 。
|
||||
- `docker/config.json` 可调整要下载的扩展和依赖库版本和链接。
|
||||
|
||||
## 目前的问题(对勾为已解决)
|
||||
- [ ] 不支持 event(libevent) 扩展,event 扩展的 sockets 支持不能在静态编译中使用,因为静态内嵌编译暂时没办法调整扩展编译顺序,同时其本身也不支持静态编译。
|
||||
- [ ] Swoole 扩展不支持 `--enable-swoole-curl`,也是因为编译顺序和加载顺序的问题。
|
||||
- [ ] 不支持 readline 扩展,readline 扩展安装后无法正常使用 `php -a`,原因还没有弄清楚,可能是静态编译造成的 ncurses 库出现了问题。
|
||||
- [X] curl/libcurl 扩展静态编译
|
||||
- [X] 可自行选择不需要编译进入的扩展
|
||||
- [ ] php.ini 内嵌或分发
|
||||
- [ ] i18n(国际化脚本本身和 README)
|
||||
|
||||
如果你对以上问题有解决方案,请提出 Issue 或 PR!
|
||||
|
||||
## 运行示例
|
||||
编译后的状态
|
||||

|
||||
|
||||
在不同系统直接运行 Swoft
|
||||

|
||||

|
||||
|
||||
## Todo List
|
||||
- [X] curl/libcurl 扩展静态编译
|
||||
- [ ] 可自行选择不需要编译进入的扩展
|
||||
- [ ] php.ini 内嵌或分发
|
||||
- [ ] 尝试带进去个 composer(其实自己下完全可以)
|
||||
直接运行 Workerman
|
||||
|
||||

|
||||
|
||||
## 参考资料
|
||||
- <https://blog.terrywh.net/post/2019/php-static-openssl/>
|
||||
|
||||
73
docker/Dockerfile
Executable file
73
docker/Dockerfile
Executable file
@@ -0,0 +1,73 @@
|
||||
FROM alpine:latest
|
||||
|
||||
# define script basic information
|
||||
# Version of this Dockerfile
|
||||
ENV SCRIPT_VERSION=1.3.3
|
||||
# Download address uses backup address
|
||||
# (if downloading slowly, consider set it to yes)
|
||||
ENV USE_BACKUP=no
|
||||
|
||||
# Version of some manually-installed package
|
||||
ENV VER_PHP=7.4.21
|
||||
|
||||
# APK repositories mirror address, if u r not in China, consider set USE_BACKUP=yes to boost
|
||||
ENV LINK_APK_REPO='mirrors.ustc.edu.cn'
|
||||
ENV LINK_APK_REPO_BAK='dl-cdn.alpinelinux.org'
|
||||
|
||||
RUN if [ "${USE_BACKUP}" = "yes" ]; then \
|
||||
echo "Using backup address..." && sleep 3s; \
|
||||
else \
|
||||
echo "Using original address..." && sleep 3s; \
|
||||
fi
|
||||
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/'${LINK_APK_REPO}'/g' /etc/apk/repositories
|
||||
|
||||
# build requirements
|
||||
RUN apk add bash wget cmake gcc g++ jq autoconf git libstdc++ linux-headers make m4 libgcc binutils ncurses
|
||||
# php zlib dependencies
|
||||
RUN apk add zlib-dev zlib-static
|
||||
# php mbstring dependencies
|
||||
RUN apk add oniguruma-dev
|
||||
# php openssl dependencies
|
||||
RUN apk add openssl-libs-static openssl-dev openssl
|
||||
# php gd dependencies
|
||||
RUN apk add libpng-dev libpng-static
|
||||
# curl c-ares dependencies
|
||||
RUN apk add c-ares-static c-ares-dev
|
||||
# php event dependencies
|
||||
RUN apk add libevent libevent-dev libevent-static
|
||||
# php sqlite3 dependencies
|
||||
RUN apk add sqlite sqlite-dev sqlite-libs sqlite-static
|
||||
|
||||
RUN mkdir /app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY ac_override_1 /app/
|
||||
COPY ac_override_2 /app/
|
||||
COPY download.sh /app/
|
||||
COPY config.json /app/
|
||||
|
||||
RUN chmod +x /app/download.sh
|
||||
|
||||
RUN ./download.sh swoole ${USE_BACKUP} && \
|
||||
./download.sh inotify ${USE_BACKUP} && \
|
||||
./download.sh mongodb ${USE_BACKUP} && \
|
||||
./download.sh event ${USE_BACKUP} && \
|
||||
./download.sh redis ${USE_BACKUP} && \
|
||||
./download.sh libxml2 ${USE_BACKUP} && \
|
||||
./download.sh liblzma ${USE_BACKUP} && \
|
||||
./download.sh curl ${USE_BACKUP}
|
||||
|
||||
RUN ./download.sh php ${USE_BACKUP} ${VER_PHP}
|
||||
|
||||
COPY extensions.txt /app/
|
||||
COPY check-extensions.sh /app/
|
||||
COPY compile-php.sh /app/
|
||||
|
||||
RUN chmod +x ./check-extensions.sh && \
|
||||
chmod +x ./compile-php.sh
|
||||
|
||||
RUN ./check-extensions.sh check_before_configure
|
||||
|
||||
RUN ./compile-php.sh ${VER_PHP}
|
||||
3
docker/ac_override_1
Executable file
3
docker/ac_override_1
Executable file
@@ -0,0 +1,3 @@
|
||||
AC_DEFUN([PHP_CHECK_LIBRARY], [
|
||||
$3
|
||||
])
|
||||
18
docker/ac_override_2
Executable file
18
docker/ac_override_2
Executable file
@@ -0,0 +1,18 @@
|
||||
AC_DEFUN([PHP_CHECK_LIBRARY], [
|
||||
save_old_LDFLAGS=$LDFLAGS
|
||||
ac_stuff="$5"
|
||||
|
||||
save_ext_shared=$ext_shared
|
||||
ext_shared=yes
|
||||
PHP_EVAL_LIBLINE([$]ac_stuff, LDFLAGS)
|
||||
AC_CHECK_LIB([$1],[$2],[
|
||||
LDFLAGS=$save_old_LDFLAGS
|
||||
ext_shared=$save_ext_shared
|
||||
$3
|
||||
],[
|
||||
LDFLAGS=$save_old_LDFLAGS
|
||||
ext_shared=$save_ext_shared
|
||||
unset ac_cv_lib_$1[]_$2
|
||||
$4
|
||||
])dnl
|
||||
])
|
||||
232
docker/check-extensions.sh
Executable file
232
docker/check-extensions.sh
Executable file
@@ -0,0 +1,232 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Here are 3 steps in configuration of extensions
|
||||
# before_configure
|
||||
# in_configure
|
||||
# after_configure
|
||||
|
||||
self_dir=$(cd "$(dirname "$0")";pwd)
|
||||
php_dir=$(find $self_dir/source -name "php-*" -type d | tail -n1)
|
||||
|
||||
function do_xml_compiler() {
|
||||
cd $self_dir/source/liblzma-* && \
|
||||
./configure && \
|
||||
make -j4 && \
|
||||
make install && \
|
||||
echo "liblzma compiled!" && sleep 2s && \
|
||||
cd ../libxml2-* && \
|
||||
./configure --prefix=/usr --with-lzma --without-python && \
|
||||
make -j4 && \
|
||||
make install && \
|
||||
echo "libxml2 compiled!" && sleep 2s
|
||||
}
|
||||
|
||||
function do_curl_compiler() {
|
||||
cd $self_dir/source/curl-* && \
|
||||
CC=gcc CXX=g++ CFLAGS=-fPIC CPPFLAGS=-fPIC ./configure \
|
||||
--without-nghttp2 \
|
||||
--with-ssl=/usr \
|
||||
--with-pic=pic \
|
||||
--enable-ipv6 \
|
||||
--enable-shared=no \
|
||||
--without-libidn2 \
|
||||
--disable-ldap \
|
||||
--without-libpsl \
|
||||
--without-lber \
|
||||
--enable-ares && \
|
||||
make -j4 && \
|
||||
make install && \
|
||||
echo "curl compiled!" && \
|
||||
cat "$self_dir/ac_override_1" "$php_dir/ext/curl/config.m4" "$self_dir/ac_override_2" > /tmp/aa && \
|
||||
mv /tmp/aa "$php_dir/ext/curl/config.m4"
|
||||
}
|
||||
|
||||
function do_copy_extension() {
|
||||
ext_dir=$(find $self_dir/source -name "$1-*" -type d | tail -n1)
|
||||
mv $ext_dir $php_dir/ext/$1
|
||||
if [ $? != 0 ]; then
|
||||
echo "Compile error! ext: $1, ext_dir=$ext_dir"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function check_before_configure() {
|
||||
list=$(cat "$self_dir/extensions.txt" | grep -v "^#" | grep -v "^$")
|
||||
xml_sign="no"
|
||||
for loop in $list
|
||||
do
|
||||
case $loop in
|
||||
bcmath) ;;
|
||||
calendar) ;;
|
||||
ctype) ;;
|
||||
filter) ;;
|
||||
gd) ;;
|
||||
hash) ;;
|
||||
iconv) ;;
|
||||
json) ;;
|
||||
mbstring) ;;
|
||||
mysqlnd) ;;
|
||||
openssl) ;;
|
||||
pcntl) ;;
|
||||
pdo) ;;
|
||||
pdo_mysql) ;;
|
||||
phar) ;;
|
||||
posix) ;;
|
||||
sockets) ;;
|
||||
sqlite3) ;;
|
||||
tokenizer) ;;
|
||||
zlib) ;;
|
||||
curl)
|
||||
do_curl_compiler
|
||||
if [ $? != 0 ]; then
|
||||
echo "Compile curl error!"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
dom|xml|libxml|xmlreader|xmlwriter|simplexml)
|
||||
if [ "$xml_sign" = "no" ]; then
|
||||
do_xml_compiler
|
||||
if [ $? != 0 ]; then
|
||||
echo "Compile curl error!"
|
||||
exit 1
|
||||
fi
|
||||
xml_sign="yes"
|
||||
fi
|
||||
;;
|
||||
inotify) do_copy_extension inotify ;;
|
||||
redis) do_copy_extension redis ;;
|
||||
swoole) do_copy_extension swoole ;;
|
||||
mongodb) do_copy_extension mongodb ;;
|
||||
event)
|
||||
PHP_EVENT=' PHP_EVENT_PHP_VERSION=$PHP_VERSION '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_EVENT_PHP_VERSION_ID=$PHP_VERSION_ID '
|
||||
PHP_EVENT="$PHP_EVENT"'\n if test -z "$PHP_EVENT_PHP_VERSION"; then '
|
||||
PHP_EVENT="$PHP_EVENT"'\n AC_MSG_ERROR(\[unknown source with no php version\]) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_EVENT_SUBDIR="." '
|
||||
PHP_EVENT="$PHP_EVENT"'\n fi '
|
||||
PHP_EVENT="$PHP_EVENT"'\n if test "$PHP_EVENT_PHP_VERSION_ID" -ge "80000"; then '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_EVENT_SUBDIR=php8 '
|
||||
PHP_EVENT="$PHP_EVENT"'\n AC_MSG_RESULT(\[PHP 8.x\]) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n elif test "$PHP_EVENT_PHP_VERSION_ID" -ge "70000"; then '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_EVENT_SUBDIR=php7 '
|
||||
PHP_EVENT="$PHP_EVENT"'\n AC_MSG_RESULT(\[PHP 7.x\]) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n elif test "$PHP_EVENT_PHP_VERSION_ID" -ge "50000"; then '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_EVENT_SUBDIR=php5 '
|
||||
PHP_EVENT="$PHP_EVENT"'\n AC_MSG_RESULT(\[PHP 5.x\]) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n else '
|
||||
PHP_EVENT="$PHP_EVENT"'\n AC_MSG_ERROR(\[unknown source lol\]) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_EVENT_SUBDIR="." '
|
||||
PHP_EVENT="$PHP_EVENT"'\n fi '
|
||||
PHP_EVENT="$PHP_EVENT"'\n echo PHP_EXT_SRCDIR(event)\/$PHP_EVENT_SUBDIR '
|
||||
PHP_EVENT="$PHP_EVENT"'\n echo PHP_EXT_BUILDDIR(event)\/$PHP_EVENT_SUBDIR '
|
||||
PHP_EVENT="$PHP_EVENT"'\n if test "$PHP_EVENT_SUBDIR" -ne "."; then '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_ADD_BUILD_DIR(PHP_EXT_SRCDIR(event)\/$PHP_EVENT_SUBDIR, 1) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_ADD_BUILD_DIR(PHP_EXT_SRCDIR(event)\/$PHP_EVENT_SUBDIR\/classes, 1) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_ADD_BUILD_DIR(PHP_EXT_SRCDIR(event)\/$PHP_EVENT_SUBDIR\/src, 1) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_ADD_INCLUDE(PHP_EXT_SRCDIR(event)\/\[$PHP_EVENT_SUBDIR\]) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_ADD_INCLUDE(PHP_EXT_SRCDIR(event)\/\[$PHP_EVENT_SUBDIR\/classes\]) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n PHP_ADD_INCLUDE(PHP_EXT_SRCDIR(event)\/\[$PHP_EVENT_SUBDIR\/src\]) '
|
||||
PHP_EVENT="$PHP_EVENT"'\n fi '
|
||||
|
||||
do_copy_extension event && \
|
||||
sed -ie 's/PHP_EVENT_SUBDIR="."//g' $php_dir/ext/event/config.m4 && \
|
||||
sed -ie 's/AC_MSG_ERROR(\[unknown source\])/'"$PHP_EVENT"'/g' $php_dir/ext/event/config.m4
|
||||
if [ $? != 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function check_in_configure() {
|
||||
php_configure=""
|
||||
list=$(cat "$self_dir/extensions.txt" | sed 's/#.*//g' | sed -e 's/[ ]*$//g' | grep -v "^\s*$")
|
||||
for loop in $list
|
||||
do
|
||||
case $loop in
|
||||
bcmath) php_configure="$php_configure --enable-bcmath" ;;
|
||||
calendar) php_configure="$php_configure --enable-calendar" ;;
|
||||
ctype) php_configure="$php_configure --enable-ctype" ;;
|
||||
curl) php_configure="$php_configure --with-curl" ;;
|
||||
dom) php_configure="$php_configure --enable-dom" ;;
|
||||
event) php_configure="$php_configure --with-event-core --with-event-extra --with-event-openssl --with-event-extra --disable-event-sockets" ;;
|
||||
filter) php_configure="$php_configure --enable-filter" ;;
|
||||
gd)
|
||||
case $1 in
|
||||
7.3.*|7.2.*) php_configure="$php_configure --with-gd" ;;
|
||||
7.4.*|8.*) php_configure="$php_configure --enable-gd" ;;
|
||||
esac
|
||||
;;
|
||||
hash)
|
||||
case $1 in
|
||||
7.3.*|7.2.*) php_configure="$php_configure --enable-hash" ;;
|
||||
esac
|
||||
;;
|
||||
iconv) php_configure="$php_configure --with-iconv" ;;
|
||||
inotify) php_configure="$php_configure --enable-inotify" ;;
|
||||
json)
|
||||
case $1 in
|
||||
7.*) php_configure="$php_configure --enable-json" ;;
|
||||
esac
|
||||
;;
|
||||
libxml)
|
||||
case $1 in
|
||||
7.3.*|7.2.*) php_configure="$php_configure --enable-libxml" ;;
|
||||
7.4.*|8.*) php_configure="$php_configure --with-libxml" ;;
|
||||
esac
|
||||
;;
|
||||
mbstring) php_configure="$php_configure --enable-mbstring" ;;
|
||||
mongodb) php_configure="$php_configure --enable-mongodb" ;;
|
||||
mysqlnd) php_configure="$php_configure --enable-mysqlnd" ;;
|
||||
openssl) php_configure="$php_configure --with-openssl --with-openssl-dir=/usr" ;;
|
||||
pcntl) php_configure="$php_configure --enable-pcntl" ;;
|
||||
pdo) php_configure="$php_configure --enable-pdo" ;;
|
||||
pdo_mysql) php_configure="$php_configure --with-pdo-mysql=mysqlnd" ;;
|
||||
phar) php_configure="$php_configure --enable-phar" ;;
|
||||
posix) php_configure="$php_configure --enable-posix" ;;
|
||||
redis) php_configure="$php_configure --enable-redis --disable-redis-session" ;;
|
||||
simplexml) php_configure="$php_configure --enable-simplexml" ;;
|
||||
sockets) php_configure="$php_configure --enable-sockets" ;;
|
||||
sqlite3) php_configure="$php_configure --with-sqlite3" ;;
|
||||
|
||||
swoole)
|
||||
php_configure="$php_configure --enable-swoole"
|
||||
have_openssl=$(echo $list | grep openssl)
|
||||
if [ "$have_openssl" != "" ]; then
|
||||
php_configure="$php_configure --enable-openssl --with-openssl --with-openssl-dir=/usr"
|
||||
fi
|
||||
have_hash=$(echo $list | grep hash)
|
||||
if [ "$have_hash" = "" ]; then
|
||||
case $1 in
|
||||
7.3.*|7.2.*) php_configure="$php_configure --enable-hash" ;;
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
tokenizer) php_configure="$php_configure --enable-tokenizer" ;;
|
||||
xml) php_configure="$php_configure --enable-xml" ;;
|
||||
xmlreader) php_configure="$php_configure --enable-xmlreader" ;;
|
||||
xmlwriter) php_configure="$php_configure --enable-xmlwriter" ;;
|
||||
zlib) php_configure="$php_configure --with-zlib" ;;
|
||||
*)
|
||||
echo "Unsupported extension '$loop' !" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo $php_configure
|
||||
}
|
||||
|
||||
function check_after_configure() {
|
||||
list=$(cat "$self_dir/extensions.txt" | grep -v "^#" | grep -v "^$")
|
||||
for loop in $list
|
||||
do
|
||||
case $loop in
|
||||
swoole)
|
||||
sed -ie 's/swoole_clock_gettime(CLOCK_REALTIME/clock_gettime(CLOCK_REALTIME/g' "$php_dir/ext/swoole/include/swoole.h"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
$1 $2
|
||||
32
docker/compile-php.sh
Executable file
32
docker/compile-php.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
VER_PHP="$1"
|
||||
|
||||
self_dir=$(cd "$(dirname "$0")";pwd)
|
||||
php_dir=$(find $self_dir/source -name "php-$VER_PHP" -type d | tail -n1)
|
||||
|
||||
function php_compile_args() {
|
||||
_php_arg="--prefix=$self_dir/php-dist"
|
||||
_php_arg="$_php_arg --disable-all"
|
||||
_php_arg="$_php_arg --enable-shared=no"
|
||||
_php_arg="$_php_arg --enable-static=yes"
|
||||
_php_arg="$_php_arg --enable-inline-optimization"
|
||||
_php_arg="$_php_arg --with-layout=GNU"
|
||||
_php_arg="$_php_arg --with-pear=no"
|
||||
_php_arg="$_php_arg --disable-cgi"
|
||||
_php_arg="$_php_arg --disable-phpdbg"
|
||||
_php_arg="$_php_arg $($self_dir/check-extensions.sh check_in_configure $1)"
|
||||
echo $_php_arg
|
||||
}
|
||||
|
||||
php_compile_args && sleep 1s
|
||||
|
||||
cd $php_dir && \
|
||||
./buildconf --force && \
|
||||
./configure LDFLAGS=-static $(php_compile_args $VER_PHP) && \
|
||||
$self_dir/check-extensions.sh check_after_configure && \
|
||||
sed -ie 's/-export-dynamic//g' "Makefile" && \
|
||||
sed -ie 's/-o $(SAPI_CLI_PATH)/-all-static -o $(SAPI_CLI_PATH)/g' "Makefile" && \
|
||||
make LDFLAGS=-ldl -j4 && \
|
||||
make install && \
|
||||
strip $self_dir/php-dist/bin/php
|
||||
46
docker/config.json
Executable file
46
docker/config.json
Executable file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"php": {
|
||||
"link": "http://mirrors.zhamao.xin/php/php-{version}.tar.gz",
|
||||
"link_2": "https://www.php.net/distributions/php-{version}.tar.gz"
|
||||
},
|
||||
"swoole": {
|
||||
"version": "4.7.0",
|
||||
"link": "http://mirrors.zhamao.xin/pecl/swoole-{version}.tgz",
|
||||
"link_2": "https://pecl.php.net/get/swoole-{version}.tgz"
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "1.9.1",
|
||||
"link": "http://mirrors.zhamao.xin/pecl/mongodb-{version}.tgz",
|
||||
"link_2": "https://pecl.php.net/get/mongodb-{version}.tgz"
|
||||
},
|
||||
"inotify": {
|
||||
"version": "3.0.0",
|
||||
"link": "http://mirrors.zhamao.xin/pecl/inotify-{version}.tgz",
|
||||
"link_2": "https://pecl.php.net/get/inotify-{version}.tgz"
|
||||
},
|
||||
"event": {
|
||||
"version": "3.0.4",
|
||||
"link": "http://mirrors.zhamao.xin/pecl/event-{version}.tgz",
|
||||
"link_2": "https://pecl.php.net/get/event-{version}.tgz"
|
||||
},
|
||||
"redis": {
|
||||
"version": "5.3.4",
|
||||
"link": "http://mirrors.zhamao.xin/pecl/redis-{version}.tgz",
|
||||
"link_2": "https://pecl.php.net/get/redis-{version}.tgz"
|
||||
},
|
||||
"libxml2": {
|
||||
"version": "2.9.10",
|
||||
"link": "https://dl.zhamao.me/libxml2/libxml2-{version}.tar.gz",
|
||||
"link_2": "http://xmlsoft.org/sources/libxml2-{version}.tar.gz"
|
||||
},
|
||||
"liblzma": {
|
||||
"version": "master",
|
||||
"link": "https://dl.zhamao.me/liblzma/liblzma.tar.gz",
|
||||
"link_2": "https://github.com/kobolabs/liblzma/archive/refs/heads/master.zip"
|
||||
},
|
||||
"curl": {
|
||||
"version": "7.78.0",
|
||||
"link": "https://dl.zhamao.me/curl/curl-{version}.tar.gz",
|
||||
"link_2": "https://curl.haxx.se/download/curl-{version}.tar.gz"
|
||||
}
|
||||
}
|
||||
59
docker/download.sh
Executable file
59
docker/download.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
|
||||
_use_backup="$2"
|
||||
|
||||
SELF_DIR=$(cd "$(dirname "$0")";pwd)
|
||||
|
||||
if [ ! -d "source" ]; then
|
||||
mkdir source
|
||||
fi
|
||||
|
||||
if [ ! -d "source/cache" ]; then
|
||||
mkdir source/cache
|
||||
fi
|
||||
|
||||
function readconf() {
|
||||
cat $SELF_DIR/config.json | jq $@ | sed 's/\"//g'
|
||||
}
|
||||
|
||||
cd source
|
||||
|
||||
if [ "$_use_backup" = "yes" ]; then
|
||||
_use_backup="_2"
|
||||
else
|
||||
_use_backup=""
|
||||
fi
|
||||
|
||||
archive_find_tar=$(find cache/ -name "$1.*" | grep -E ".tgz" | tail -n1)
|
||||
archive_find_zip=$(find cache/ -name "$1.*" | grep -E ".zip" | tail -n1)
|
||||
|
||||
if [ "$archive_find_tar" != "" ]; then
|
||||
echo "Using cache for $1 ($archive_find_tar)"
|
||||
tar -zxvf "$archive_find_tar"
|
||||
elif [ "$archive_find_zip" != "" ]; then
|
||||
echo "Using cache for $1 ($archive_find_zip)"
|
||||
unzip $archive_find_zip -d "$SELF_DIR/source"
|
||||
else
|
||||
if [ "$3" != "" ]; then
|
||||
wget -q --show-progress "$(readconf ".$1.link$_use_backup" | sed 's/{version}/'$3'/g')"
|
||||
else
|
||||
echo "Downloading"
|
||||
wget -q --show-progress "$(readconf ".$1.link$_use_backup" | sed 's/{version}/'$(readconf ".$1.version")'/g')"
|
||||
fi
|
||||
|
||||
if [ $? == 0 ]; then
|
||||
archive_file_tar=$(find . -name "$1*.*" | grep -E ".tar|.gz|.tgz" | tail -n1)
|
||||
archive_file_zip=$(find . -name "*.zip" | tail -n1)
|
||||
if [ "$archive_file_tar" != "" ]; then
|
||||
tar -zxvf $archive_file_tar && mv $archive_file_tar $SELF_DIR/source/cache/$1.tgz
|
||||
elif [ "$archive_file_zip" != "" ]; then
|
||||
unzip $archive_file_zip && mv $archive_file_zip $SELF_DIR/source/cache/$1.zip
|
||||
else
|
||||
echo "Unable to find downloaded file, only support '.tar.gz', '.tgz', '.zip' file!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Download $1 failed! (at $?)"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
31
docker/extensions.txt
Executable file
31
docker/extensions.txt
Executable file
@@ -0,0 +1,31 @@
|
||||
bcmath
|
||||
calendar
|
||||
ctype
|
||||
curl
|
||||
dom
|
||||
filter
|
||||
gd
|
||||
hash
|
||||
iconv
|
||||
inotify
|
||||
json
|
||||
libxml
|
||||
mbstring
|
||||
#mongodb
|
||||
mysqlnd
|
||||
openssl
|
||||
pcntl
|
||||
pdo
|
||||
pdo_mysql
|
||||
phar
|
||||
posix
|
||||
redis
|
||||
simplexml
|
||||
sockets
|
||||
sqlite3
|
||||
swoole
|
||||
tokenizer
|
||||
xml
|
||||
xmlreader
|
||||
xmlwriter
|
||||
zlib
|
||||
50
docker/fast-compiler.sh
Executable file
50
docker/fast-compiler.sh
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script needs alpine linux system.
|
||||
|
||||
VER_PHP="7.4.21"
|
||||
USE_BACKUP="no"
|
||||
|
||||
LINK_APK_REPO='mirrors.ustc.edu.cn'
|
||||
LINK_APK_REPO_BAK='dl-cdn.alpinelinux.org'
|
||||
|
||||
if [ "${USE_BACKUP}" = "yes" ]; then \
|
||||
echo "Using backup address..." && sleep 1s
|
||||
LINK_APK_REPO=${LINK_APK_REPO_BAK}
|
||||
else
|
||||
echo "Using original address..." && sleep 1s
|
||||
fi
|
||||
|
||||
sed -i 's/dl-cdn.alpinelinux.org/'${LINK_APK_REPO}'/g' /etc/apk/repositories
|
||||
|
||||
# build requirements
|
||||
apk add bash wget cmake gcc g++ jq autoconf git libstdc++ linux-headers make m4 libgcc binutils ncurses
|
||||
# php zlib dependencies
|
||||
apk add zlib-dev zlib-static
|
||||
# php mbstring dependencies
|
||||
apk add oniguruma-dev
|
||||
# php openssl dependencies
|
||||
apk add openssl-libs-static openssl-dev openssl
|
||||
# php gd dependencies
|
||||
apk add libpng-dev libpng-static
|
||||
# curl c-ares dependencies
|
||||
apk add c-ares-static c-ares-dev
|
||||
# php event dependencies
|
||||
apk add libevent libevent-dev libevent-static
|
||||
# php sqlite3 dependencies
|
||||
apk add sqlite sqlite-dev sqlite-libs sqlite-static
|
||||
|
||||
chmod +x download.sh check-extensions.sh compile-php.sh
|
||||
|
||||
./download.sh swoole ${USE_BACKUP} && \
|
||||
./download.sh inotify ${USE_BACKUP} && \
|
||||
./download.sh mongodb ${USE_BACKUP} && \
|
||||
./download.sh event ${USE_BACKUP} && \
|
||||
./download.sh redis ${USE_BACKUP} && \
|
||||
./download.sh libxml2 ${USE_BACKUP} && \
|
||||
./download.sh liblzma ${USE_BACKUP} && \
|
||||
./download.sh curl ${USE_BACKUP} && \
|
||||
./download.sh php ${USE_BACKUP} ${VER_PHP} && \
|
||||
./check-extensions.sh check_before_configure && \
|
||||
./compile-php.sh ${VER_PHP}
|
||||
|
||||
66
docker/multi-version-compiler.sh
Executable file
66
docker/multi-version-compiler.sh
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/bin/sh
|
||||
|
||||
USE_BACKUP="no"
|
||||
|
||||
LINK_APK_REPO='mirrors.ustc.edu.cn'
|
||||
LINK_APK_REPO_BAK='dl-cdn.alpinelinux.org'
|
||||
|
||||
if [ "${USE_BACKUP}" = "yes" ]; then \
|
||||
echo "Using backup address..." && sleep 1s
|
||||
LINK_APK_REPO=${LINK_APK_REPO_BAK}
|
||||
else
|
||||
echo "Using original address..." && sleep 1s
|
||||
fi
|
||||
|
||||
sed -i 's/dl-cdn.alpinelinux.org/'${LINK_APK_REPO}'/g' /etc/apk/repositories
|
||||
|
||||
# build requirements
|
||||
apk add bash wget cmake gcc g++ jq autoconf git libstdc++ linux-headers make m4 libgcc binutils ncurses
|
||||
# php zlib dependencies
|
||||
apk add zlib-dev zlib-static
|
||||
# php mbstring dependencies
|
||||
apk add oniguruma-dev
|
||||
# php openssl dependencies
|
||||
apk add openssl-libs-static openssl-dev openssl
|
||||
# php gd dependencies
|
||||
apk add libpng-dev libpng-static
|
||||
# curl c-ares dependencies
|
||||
apk add c-ares-static c-ares-dev
|
||||
# php event dependencies
|
||||
apk add libevent libevent-dev libevent-static
|
||||
# php sqlite3 dependencies
|
||||
apk add sqlite sqlite-dev sqlite-libs sqlite-static
|
||||
|
||||
chmod +x download.sh check-extensions.sh compile-php.sh
|
||||
|
||||
./download.sh swoole ${USE_BACKUP} && \
|
||||
./download.sh inotify ${USE_BACKUP} && \
|
||||
./download.sh mongodb ${USE_BACKUP} && \
|
||||
./download.sh event ${USE_BACKUP} && \
|
||||
./download.sh redis ${USE_BACKUP} && \
|
||||
./download.sh libxml2 ${USE_BACKUP} && \
|
||||
./download.sh liblzma ${USE_BACKUP} && \
|
||||
./download.sh curl ${USE_BACKUP}
|
||||
|
||||
if [ ! -d "multi-build" ]; then
|
||||
mkdir ./multi-build
|
||||
fi
|
||||
|
||||
for VER_PHP in "7.2.34" "7.3.29" "7.4.21" "8.0.8"
|
||||
do
|
||||
./download.sh swoole ${USE_BACKUP} && \
|
||||
./download.sh inotify ${USE_BACKUP} && \
|
||||
./download.sh mongodb ${USE_BACKUP} && \
|
||||
./download.sh event ${USE_BACKUP} && \
|
||||
./download.sh redis ${USE_BACKUP} && \
|
||||
./download.sh libxml2 ${USE_BACKUP} && \
|
||||
./download.sh liblzma ${USE_BACKUP} && \
|
||||
./download.sh curl ${USE_BACKUP} && \
|
||||
./download.sh php ${USE_BACKUP} ${VER_PHP} && \
|
||||
./check-extensions.sh check_before_configure && \
|
||||
./compile-php.sh ${VER_PHP} && \
|
||||
cp ./php-dist/bin/php ./multi-build/php-${VER_PHP} && \
|
||||
rm -rf ./source
|
||||
done
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
_main_dir="$(pwd)/"
|
||||
|
||||
_build_dir="$_main_dir/build"
|
||||
|
||||
mkdir "$_build_dir" > /dev/null 2>&1
|
||||
|
||||
for loop in "7.4.16" "8.0.3"
|
||||
do
|
||||
sed -i 's/_php_ver=.*/_php_ver="'$loop'"/g' "$_main_dir""static-compile-php.sh" && \
|
||||
rm -rf "$_main_dir""source/php.tar.gz" "$_main_dir""source/php-*" "$_main_dir""php-dist" && \
|
||||
"$_main_dir""static-compile-php.sh" && \
|
||||
cp "$_main_dir""php-dist/bin/php" "$_build_dir/" && \
|
||||
cd "$_build_dir/" && \
|
||||
tar -zcvf "php-$loop-static-bin-"$(uname -m)".tar.gz" "./php" && \
|
||||
mv "./php" "./php-$loop" && \
|
||||
cd "$_main_dir"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Compile static php-$loop failed!"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
@@ -1,245 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function downloadIt() {
|
||||
downloader="wget"
|
||||
type wget >/dev/null 2>&1 || { downloader="curl"; }
|
||||
if [ "$downloader" = "wget" ]; then
|
||||
_down_prefix="O"
|
||||
else
|
||||
_down_prefix="o"
|
||||
fi
|
||||
_down_symbol=0
|
||||
if [ ! -f "$2" ]; then
|
||||
$downloader "$1" -$_down_prefix "$2" >/dev/null 2>&1 && \
|
||||
echo "$1 完成!" && _down_symbol=1
|
||||
else
|
||||
echo "$1 已存在!" && _down_symbol=1
|
||||
fi
|
||||
if [ $_down_symbol == 0 ]; then
|
||||
echo "失败!请检查网络连接!"
|
||||
rm -rf "$2"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_script_ver="1.1.1"
|
||||
|
||||
_php_ver="7.4.16"
|
||||
_swoole_ver="4.6.6"
|
||||
_redis_ver="5.3.4"
|
||||
_libxml2_ver="2.9.10"
|
||||
_curl_ver="7.76.1"
|
||||
|
||||
# 默认编译在脚本当前目录
|
||||
_home_dir=$(pwd)"/"
|
||||
|
||||
# PHP使用国内的搜狐镜像
|
||||
_php_down_link="http://mirrors.sohu.com/php/php-$_php_ver.tar.gz"
|
||||
# swoole使用自建的炸毛服务器的分发,因为pecl有时候在国内奇慢
|
||||
_swoole_down_link="https://dl.zhamao.me/swoole/swoole-$_swoole_ver.tgz"
|
||||
_swoole_down_link_bak="https://pecl.php.net/get/swoole-$_swoole_ver.tgz"
|
||||
# phpredis也使用自建的炸毛服务器分发
|
||||
_redis_down_link="https://dl.zhamao.me/phpredis/redis-$_redis_ver.tgz"
|
||||
_redis_down_link_bak="https://pecl.php.net/get/redis-$_redis_ver.tgz"
|
||||
# libxml2也使用自建的服务器
|
||||
_libxml2_down_link="https://dl.zhamao.me/libxml2/libxml2-$_libxml2_ver.tar.gz"
|
||||
_libxml2_down_link_bak="http://xmlsoft.org/sources/libxml2-$_libxml2_ver.tar.gz"
|
||||
# liblzma是自建的服务器,如果需要找原始位置,在GitHub搜索liblzma即可
|
||||
_liblzma_down_link="https://dl.zhamao.me/liblzma/liblzma.tar.gz"
|
||||
# curl/libcurl使用自建的服务器,bak是源地址
|
||||
_curl_down_link="https://dl.zhamao.me/curl/curl-$_curl_ver.tar.gz"
|
||||
_curl_down_link_bak="https://curl.haxx.se/download/curl-$_curl_ver.tar.gz"
|
||||
|
||||
_curl_override_1='
|
||||
AC_DEFUN([PHP_CHECK_LIBRARY], [
|
||||
$3
|
||||
])
|
||||
'
|
||||
|
||||
_curl_override_2='
|
||||
AC_DEFUN([PHP_CHECK_LIBRARY], [
|
||||
save_old_LDFLAGS=$LDFLAGS
|
||||
ac_stuff="$5"
|
||||
|
||||
save_ext_shared=$ext_shared
|
||||
ext_shared=yes
|
||||
PHP_EVAL_LIBLINE([$]ac_stuff, LDFLAGS)
|
||||
AC_CHECK_LIB([$1],[$2],[
|
||||
LDFLAGS=$save_old_LDFLAGS
|
||||
ext_shared=$save_ext_shared
|
||||
$3
|
||||
],[
|
||||
LDFLAGS=$save_old_LDFLAGS
|
||||
ext_shared=$save_ext_shared
|
||||
unset ac_cv_lib_$1[]_$2
|
||||
$4
|
||||
])dnl
|
||||
])
|
||||
'
|
||||
|
||||
function downloadAll() {
|
||||
mkdir "$_home_dir""source" > /dev/null 2>&1
|
||||
|
||||
echo "正在下载 php 源码 "$_php_down_link" ..."
|
||||
downloadIt $_php_down_link "$_home_dir""source/php.tar.gz" || { exit 1; } &
|
||||
|
||||
#echo "正在下载 openssl 源码 "$_openssl_down_link" ..."
|
||||
#downloadIt $_openssl_down_link "$_home_dir""source/openssl.tar.gz" || { exit; } &
|
||||
|
||||
echo "正在下载 swoole 源码 "$_swoole_down_link" ..."
|
||||
downloadIt $_swoole_down_link "$_home_dir""source/swoole.tar.gz" || { exit 1; } &
|
||||
|
||||
echo "正在下载 redis 源码 "$_redis_down_link" ..."
|
||||
downloadIt $_redis_down_link "$_home_dir""source/redis.tar.gz" || { exit 1; } &
|
||||
|
||||
echo "正在下载 libxml2 源码 ..."
|
||||
downloadIt $_libxml2_down_link "$_home_dir""source/libxml2.tar.gz" || { exit 1; } &
|
||||
|
||||
echo "正在下载 liblzma 源码 ..."
|
||||
downloadIt $_liblzma_down_link "$_home_dir""source/liblzma.tar.gz" || { exit 1; } &
|
||||
|
||||
echo "正在下载 curl 源码 ..."
|
||||
downloadIt $_curl_down_link "$_home_dir""source/curl.tar.gz" || { exit 1; } &
|
||||
|
||||
wait
|
||||
}
|
||||
|
||||
function compileLiblzma() {
|
||||
if [ -f "$_home_dir""opt/liblzma/lib/liblzma.so" ]; then
|
||||
echo "已编译 liblzma!" && return
|
||||
fi
|
||||
tar -xf "$_home_dir""source/liblzma.tar.gz" -C "$_home_dir""source/" && \
|
||||
cd "$_home_dir""source/liblzma" && \
|
||||
./configure --prefix="$_home_dir""opt/liblzma" && \
|
||||
make -j4 && \
|
||||
make install && \
|
||||
echo "编译 liblzma 完成!"
|
||||
}
|
||||
|
||||
function compileCurl() {
|
||||
if [ -f "$_home_dir""opt/curl/bin/curl" ]; then
|
||||
echo "已编译 curl!" && return
|
||||
fi
|
||||
tar -xf "$_home_dir""source/curl.tar.gz" -C "$_home_dir""source/" && \
|
||||
cd "$_home_dir""source/curl-""$_curl_ver" && \
|
||||
CC=gcc CXX=g++ CFLAGS=-fPIC CPPFLAGS=-fPIC ./configure --prefix="$_home_dir""opt/curl" \
|
||||
--without-nghttp2 \
|
||||
--with-ssl=/usr \
|
||||
--with-pic=pic \
|
||||
--enable-ipv6 \
|
||||
--enable-shared=no \
|
||||
--without-libidn2 \
|
||||
--disable-ldap \
|
||||
--without-libpsl \
|
||||
--without-lber \
|
||||
--enable-ares && \
|
||||
make -j4 && \
|
||||
make install && \
|
||||
echo "编译 curl 完成!"
|
||||
}
|
||||
|
||||
function compileLibxml2() {
|
||||
if [ -f "$_home_dir""opt/libxml2/lib/libxml2.so" ]; then
|
||||
echo "已编译 libxml2!" && return
|
||||
fi
|
||||
tar -xf "$_home_dir""source/libxml2.tar.gz" -C "$_home_dir""source/" && \
|
||||
cd "$_home_dir""source/libxml2-""$_libxml2_ver" && \
|
||||
./configure --with-lzma="$_home_dir""opt/liblzma" --prefix="$_home_dir""opt/libxml2" --exec-prefix="$_home_dir""opt/libxml2" --without-python && \
|
||||
make -j4 && \
|
||||
make install && \
|
||||
echo "编译 libxml2 完成!"
|
||||
}
|
||||
|
||||
function compilePHPWithSwoole() {
|
||||
echo "正在编译 php ..." && \
|
||||
rm -rf "$_home_dir""source/php-""$_php_ver" && \
|
||||
tar -xf "$_home_dir""source/php.tar.gz" -C "$_home_dir""source/" && \
|
||||
#git clone --depth=1 https://fgit.zhamao.me/swoole/swoole-src.git "$_home_dir""source/"swoole-$_swoole_ver && \
|
||||
tar -xf "$_home_dir""source/swoole.tar.gz" -C "$_home_dir""source/" && \
|
||||
mv "$_home_dir""source/swoole-""$_swoole_ver" "$_home_dir""source/php-""$_php_ver/ext/swoole" && \
|
||||
"$_home_dir""source/php-""$_php_ver/ext/swoole/clear.sh" && \
|
||||
tar -xf "$_home_dir""source/redis.tar.gz" -C "$_home_dir""source/" && \
|
||||
mv "$_home_dir""source/redis-""$_redis_ver" "$_home_dir""source/php-""$_php_ver/ext/redis" && \
|
||||
cd "$_home_dir""source/php-""$_php_ver/" && \
|
||||
echo "$_curl_override_1" > "$_home_dir""ac_override_1" && \
|
||||
echo "$_curl_override_2" > "$_home_dir""ac_override_2" && \
|
||||
cat "$_home_dir""ac_override_1" "$_home_dir""source/php-""$_php_ver/ext/curl/config.m4" "$_home_dir""ac_override_2" > /tmp/aa && \
|
||||
mv /tmp/aa "$_home_dir""source/php-""$_php_ver/ext/curl/config.m4" && \
|
||||
./buildconf --force && \
|
||||
PKG_CONFIG_PATH="$PKG_CONFIG_PATH:""$_home_dir""opt/libxml2/lib/pkgconfig" && \
|
||||
PKG_CONFIG_PATH="$PKG_CONFIG_PATH:""$_home_dir""opt/curl/lib/pkgconfig" ./configure LDFLAGS=-static \
|
||||
--prefix="$_home_dir""php-dist" \
|
||||
--disable-all \
|
||||
--enable-shared=no \
|
||||
--enable-static=yes \
|
||||
--enable-inline-optimization \
|
||||
--with-layout=GNU \
|
||||
--enable-calendar \
|
||||
--enable-ctype \
|
||||
--enable-filter \
|
||||
--enable-openssl \
|
||||
--enable-bcmath \
|
||||
--with-openssl-dir="/usr" \
|
||||
--enable-pcntl \
|
||||
--enable-openssl \
|
||||
--with-openssl \
|
||||
--with-iconv \
|
||||
--enable-json \
|
||||
--enable-mbstring \
|
||||
--enable-phar \
|
||||
--enable-pdo \
|
||||
--with-pdo-mysql=mysqlnd \
|
||||
--enable-sockets \
|
||||
--enable-swoole \
|
||||
--enable-gd \
|
||||
--enable-redis \
|
||||
--disable-redis-session \
|
||||
--enable-simplexml \
|
||||
--enable-dom \
|
||||
--with-libxml="$_home_dir""opt/libxml2" \
|
||||
--enable-xml \
|
||||
--enable-xmlwriter \
|
||||
--enable-xmlreader \
|
||||
--with-zlib \
|
||||
--enable-posix \
|
||||
--enable-mysqlnd \
|
||||
--enable-tokenizer \
|
||||
--with-curl="$_home_dir""opt/curl" \
|
||||
--with-pear=no \
|
||||
--disable-pear \
|
||||
--disable-cgi \
|
||||
--disable-phpdbg && \
|
||||
sed -ie 's/-export-dynamic//g' "$_home_dir""source/php-""$_php_ver/Makefile" && \
|
||||
sed -ie 's/-o $(SAPI_CLI_PATH)/-all-static -o $(SAPI_CLI_PATH)/g' "$_home_dir""source/php-""$_php_ver/Makefile" && \
|
||||
sed -ie 's/swoole_clock_gettime(CLOCK_REALTIME/clock_gettime(CLOCK_REALTIME/g' "$_home_dir""source/php-""$_php_ver/ext/swoole/include/swoole.h" && \
|
||||
make LDFLAGS=-ldl -j4 && \
|
||||
make install && \
|
||||
strip "$_home_dir""php-dist/bin/php"
|
||||
}
|
||||
|
||||
#apk add g++ pkgconf autoconf nghttp2 libcurl \
|
||||
# git gcc zlib-dev libstdc++ ncurses zlib linux-headers \
|
||||
# readline make libssl1.1 libxml2 m4 libgcc vim binutils \
|
||||
# oniguruma-dev openssl openssl-dev
|
||||
# 编译必需的
|
||||
apk add gcc g++ autoconf libstdc++ linux-headers make m4 libgcc binutils ncurses
|
||||
# php的zlib支持
|
||||
apk add zlib-dev zlib-static
|
||||
# php的mbstring支持
|
||||
apk add oniguruma-dev
|
||||
# php的openssl支持
|
||||
apk add openssl-libs-static openssl-dev openssl
|
||||
# php的gd支持,如果不需要gd则去掉--enable-gd和下面的依赖
|
||||
apk add libpng-dev libpng-static
|
||||
# curl的c-ares支持,如果不需要curl则去掉
|
||||
apk add c-ares-static c-ares-dev
|
||||
|
||||
|
||||
downloadAll && \
|
||||
compileLiblzma && \
|
||||
compileLibxml2 && \
|
||||
compileCurl && \
|
||||
compilePHPWithSwoole && \
|
||||
echo "完成!见 php-dist/bin/php"
|
||||
|
||||
Reference in New Issue
Block a user