Skip to content

Commit d0e4c17

Browse files
authored
Merge pull request #954 from jingjingxyk/build_native_php
Build native php
2 parents 479ec68 + 5e3c282 commit d0e4c17

File tree

5 files changed

+153
-59
lines changed

5 files changed

+153
-59
lines changed

.github/workflows/artifact-hash.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
version:
77
required: true
88
description: "发版 版本号 tag"
9-
default: 'v1.9.1'
9+
default: 'v1.9.2'
1010
type: string
1111
php-version:
1212
required: true
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v4
2626
- name: Show Release File Hash
2727
run: |
28-
bash sapi/scripts/generate-artifact-hash.sh --version ${{ inputs.version }} --php-version ${{ inputs.php-version }}
28+
bash sapi/scripts/generate-artifact-hash.sh --version ${{ inputs.version }} --with-php-versions ${{ inputs.php-version }}
2929
3030
- name: production artifacts
3131
uses: actions/upload-artifact@v4

sapi/download-box/download-box-get-archive-from-server.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ if [ -f "${__PROJECT__}/sapi/PHP-VERSION.conf" ]; then
2222
DOMAIN='https://github.com/swoole/swoole-cli/releases/download/v6.0.0.0/'
2323
ALL_DEPS_HASH="a55699ecee994032f33266dfa37eabb49f1f6d6b6b65cdcf7b881cac09c63bea"
2424
else
25-
DOMAIN='https://github.com/swoole/build-static-php/releases/download/v1.6.0/'
26-
ALL_DEPS_HASH="771f8c695477be93da10847f3051fb054f0f829b242300e1ae2126b67f338664"
25+
DOMAIN='https://github.com/swoole/build-static-php/releases/download/v1.9.2/'
26+
ALL_DEPS_HASH="4e840ca7d9fb2342a7d459282c7e403921a892ed4eebea4b1a6db48d790bf1ee"
2727
fi
2828

2929
while [ $# -gt 0 ]; do
@@ -47,6 +47,10 @@ URL="${DOMAIN}/all-deps.zip"
4747

4848
test -f all-deps.zip || curl -fSLo all-deps.zip ${URL}
4949

50+
# https://www.runoob.com/linux/linux-comm-unzip.html
51+
# -o 不必先询问用户,unzip执行后覆盖原有文件。
52+
# -n 解压缩时不要覆盖原有的文件。
53+
5054
# hash 签名
5155
HASH=$(sha256sum all-deps.zip | awk '{print $1}')
5256

@@ -62,9 +66,11 @@ fi
6266

6367
unzip -n all-deps.zip
6468

69+
6570
cd ${__PROJECT__}/
6671

6772
awk 'BEGIN { cmd="cp -ri var/download-box/lib/* pool/lib" ; print "n" |cmd; }'
6873
awk 'BEGIN { cmd="cp -ri var/download-box/ext/* pool/ext"; print "n" |cmd; }'
6974

75+
7076
echo "download all-archive.zip ok !"

sapi/scripts/generate-artifact-hash.sh

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ __PROJECT__=$(
1313
cd ${__PROJECT__}
1414

1515
OS=$(uname -s)
16+
ARCH=$(uname -m)
1617
case $OS in
1718
'Linux')
1819
OS="linux"
@@ -36,9 +37,23 @@ case $OS in
3637
;;
3738
esac
3839

40+
case $ARCH in
41+
'x86_64')
42+
ARCH="x64"
43+
;;
44+
'aarch64' | 'arm64')
45+
ARCH="arm64"
46+
;;
47+
*)
48+
echo '暂未配置的 ARCH '
49+
exit 0
50+
;;
51+
esac
52+
3953
APP_VERSION='v8.3.19'
4054
APP_NAME='php-cli'
41-
VERSION='v1.9.1'
55+
VERSION='v1.9.2'
56+
PHP_VERSIONS=""
4257

4358
while [ $# -gt 0 ]; do
4459
case "$1" in
@@ -103,6 +118,13 @@ while [ $# -gt 0 ]; do
103118
}
104119
fi
105120
;;
121+
--with-php-versions)
122+
OLD_IFS=$IFS
123+
IFS=','
124+
read -r -a PHP_VERSIONS <<<"$2"
125+
IFS=$OLD_IFS
126+
echo "${PHP_VERSIONS[@]}"
127+
;;
106128
--*)
107129
echo "Illegal option $1"
108130
exit 0
@@ -127,14 +149,6 @@ UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME() {
127149
test -f ${APP_RUNTIME}.tar.xz || curl -fSLo ${APP_RUNTIME}.tar.xz ${APP_DOWNLOAD_URL}
128150
}
129151

130-
UNIX_DOWNLOAD() {
131-
APP_VERSION="$1"
132-
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "linux" "x64" "${APP_VERSION}"
133-
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "linux" "arm64" "${APP_VERSION}"
134-
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "macos" "x64" "${APP_VERSION}"
135-
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "macos" "arm64" "${APP_VERSION}"
136-
}
137-
138152
WINDOWS_DOWNLOAD_SWOOLE_CLIE_RUNTIME() {
139153
APP_VERSION="$1"
140154
ARCH="x64"
@@ -143,31 +157,39 @@ WINDOWS_DOWNLOAD_SWOOLE_CLIE_RUNTIME() {
143157
APP_RUNTIME="${APP_NAME}-${APP_VERSION}-cygwin-${ARCH}"
144158
test -f ${APP_RUNTIME}.zip || curl -fSLo ${APP_RUNTIME}.zip ${APP_DOWNLOAD_URL}
145159
}
146-
WINDOWS_DOWNLOAD() {
147-
WINDOWS_DOWNLOAD_SWOOLE_CLIE_RUNTIME "$1"
148-
}
149160

150-
RUN_DOWNLOAD() {
151-
UNIX_DOWNLOAD "$1"
152-
WINDOWS_DOWNLOAD "$1"
161+
UNIX_DOWNLOAD() {
162+
APP_VERSION="$1"
163+
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "linux" "x64" "${APP_VERSION}"
164+
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "linux" "arm64" "${APP_VERSION}"
165+
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "macos" "x64" "${APP_VERSION}"
166+
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "macos" "arm64" "${APP_VERSION}"
153167
}
154168

155169
DOWNLOAD() {
156170
declare -A PHP_VERSIONS
157-
PHP_VERSIONS[0]="v8.2.27"
158-
PHP_VERSIONS[1]="v8.1.31"
159-
PHP_VERSIONS[2]="v8.3.15"
160-
PHP_VERSIONS[3]="v8.4.2"
171+
PHP_VERSIONS[0]="v8.2.28"
172+
PHP_VERSIONS[1]="v8.1.32"
173+
PHP_VERSIONS[2]="v8.3.19"
174+
PHP_VERSIONS[3]="v8.4.5"
161175
for i in "${!PHP_VERSIONS[@]}"; do
162176
# echo ${PHP_VERSIONS[$i]}
163-
RUN_DOWNLOAD "${PHP_VERSIONS[$i]}"
177+
UNIX_DOWNLOAD "${PHP_VERSIONS[$i]}"
178+
WINDOWS_DOWNLOAD_SWOOLE_CLIE_RUNTIME "${PHP_VERSIONS[$i]}"
164179
done
165-
166180
}
167181

168-
test -f all-deps.zip || curl -fSLo all-deps.zip https://github.com/swoole/build-static-php/releases/download/${VERSION}/all-deps.zip
169-
170-
DOWNLOAD
182+
if [ -n "$PHP_VERSIONS" ]; then
183+
for i in "${!PHP_VERSIONS[@]}"; do
184+
# echo ${PHP_VERSIONS[$i]}
185+
# RUN_DOWNLOAD "${PHP_VERSIONS[$i]}"
186+
UNIX_DOWNLOAD "${PHP_VERSIONS[$i]}"
187+
WINDOWS_DOWNLOAD_SWOOLE_CLIE_RUNTIME "${PHP_VERSIONS[$i]}"
188+
done
189+
test -f all-deps.zip || curl -fSLo all-deps.zip https://github.com/swoole/build-static-php/releases/download/${VERSION}/all-deps.zip
190+
else
191+
UNIX_DOWNLOAD_SWOOLE_CLIE_RUNTIME "${OS}" "${ARCH}" "${APP_VERSION}"
192+
fi
171193

172194
ls -p | grep -v '/$' | xargs sha256sum
173195

setup-php-cli-runtime.sh

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ __DIR__=$(
66
pwd
77
)
88
__PROJECT__=${__DIR__}
9-
9+
shopt -s expand_aliases
1010
cd ${__PROJECT__}
1111

1212
OS=$(uname -s)
@@ -50,10 +50,15 @@ esac
5050

5151
APP_VERSION='v8.2.28'
5252
APP_NAME='php-cli'
53-
VERSION='v1.9.0'
53+
VERSION='v1.9.2'
5454

55-
mkdir -p bin/runtime
55+
cd ${__PROJECT__}
56+
mkdir -p runtime/
5657
mkdir -p var/runtime
58+
APP_RUNTIME_DIR=${__PROJECT__}/runtime/${APP_NAME}
59+
mkdir -p ${APP_RUNTIME_DIR}
60+
61+
cd ${__PROJECT__}/var/runtime
5762

5863
MIRROR=''
5964
while [ $# -gt 0 ]; do
@@ -142,25 +147,24 @@ if [ $OS = 'windows' ]; then
142147
test -f ${APP_RUNTIME}.zip || curl -LSo ${APP_RUNTIME}.zip ${APP_DOWNLOAD_URL}
143148
test -d ${APP_RUNTIME} && rm -rf ${APP_RUNTIME}
144149
unzip "${APP_RUNTIME}.zip"
145-
echo
146150
exit 0
147151
}
148152
else
149153
test -f ${APP_RUNTIME}.tar.xz || curl -LSo ${APP_RUNTIME}.tar.xz ${APP_DOWNLOAD_URL}
150154
test -f ${APP_RUNTIME}.tar || xz -d -k ${APP_RUNTIME}.tar.xz
151155
test -f php || tar -xvf ${APP_RUNTIME}.tar
152156
chmod a+x php
153-
cp -f ${__PROJECT__}/var/runtime/php ${__PROJECT__}/bin/runtime/php
157+
cp -f ${__PROJECT__}/var/runtime/php ${APP_RUNTIME_DIR}/
154158
fi
155159

156160
cd ${__PROJECT__}/var/runtime
157161

158-
cp -f ${__PROJECT__}/var/runtime/composer.phar ${__PROJECT__}/bin/runtime/composer
159-
cp -f ${__PROJECT__}/var/runtime/cacert.pem ${__PROJECT__}/bin/runtime/cacert.pem
162+
cp -f ${__PROJECT__}/var/runtime/composer.phar ${APP_RUNTIME_DIR}/composer
163+
cp -f ${__PROJECT__}/var/runtime/cacert.pem ${APP_RUNTIME_DIR}/cacert.pem
160164

161-
cat >${__PROJECT__}/bin/runtime/php.ini <<EOF
162-
curl.cainfo="${__PROJECT__}/bin/runtime/cacert.pem"
163-
openssl.cafile="${__PROJECT__}/bin/runtime/cacert.pem"
165+
cat >${APP_RUNTIME_DIR}/php.ini <<EOF
166+
curl.cainfo="${APP_RUNTIME_DIR}/cacert.pem"
167+
openssl.cafile="${APP_RUNTIME_DIR}/cacert.pem"
164168
swoole.use_shortname=off
165169
display_errors = On
166170
error_reporting = E_ALL
@@ -186,10 +190,10 @@ set +x
186190
echo " "
187191
echo " USE PHP-CLI RUNTIME :"
188192
echo " "
189-
echo " export PATH=\"${__PROJECT__}/bin/runtime:\$PATH\" "
193+
echo " export PATH=\"${APP_RUNTIME_DIR}:\$PATH\" "
190194
echo " "
191-
echo " alias php='php -d curl.cainfo=${__PROJECT__}/bin/runtime/cacert.pem -d openssl.cafile=${__PROJECT__}/bin/runtime/cacert.pem' "
195+
echo " alias php='php -d curl.cainfo=${APP_RUNTIME_DIR}/cacert.pem -d openssl.cafile=${APP_RUNTIME_DIR}/cacert.pem' "
192196
echo " OR "
193-
echo " alias php='php -c ${__PROJECT__}/bin/runtime/php.ini' "
197+
echo " alias php='php -c ${APP_RUNTIME_DIR}/php.ini' "
194198
echo " "
195199
echo " PHP-CLI VERSION ${APP_VERSION}"

setup-php-fpm-runtime.sh

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ __DIR__=$(
66
pwd
77
)
88
__PROJECT__=${__DIR__}
9-
9+
shopt -s expand_aliases
1010
cd ${__PROJECT__}
1111

1212
OS=$(uname -s)
@@ -50,10 +50,7 @@ esac
5050

5151
APP_VERSION='v8.2.28'
5252
APP_NAME='php-fpm'
53-
VERSION='php-fpm-v2.1.0'
54-
55-
mkdir -p bin/runtime
56-
mkdir -p var/runtime
53+
VERSION='php-fpm-v2.2.0'
5754

5855
MIRROR=''
5956
while [ $# -gt 0 ]; do
@@ -108,6 +105,12 @@ while [ $# -gt 0 ]; do
108105
shift $(($# > 0 ? 1 : 0))
109106
done
110107

108+
cd ${__PROJECT__}
109+
mkdir -p runtime/
110+
mkdir -p var/runtime
111+
APP_RUNTIME_DIR=${__PROJECT__}/runtime/${APP_NAME}
112+
mkdir -p ${APP_RUNTIME_DIR}
113+
111114
cd ${__PROJECT__}/var/runtime
112115

113116
APP_DOWNLOAD_URL="https://github.com/swoole/build-static-php/releases/download/${VERSION}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"
@@ -142,25 +145,27 @@ if [ $OS = 'windows' ]; then
142145
test -f ${APP_RUNTIME}.zip || curl -LSo ${APP_RUNTIME}.zip ${APP_DOWNLOAD_URL}
143146
test -d ${APP_RUNTIME} && rm -rf ${APP_RUNTIME}
144147
unzip "${APP_RUNTIME}.zip"
145-
echo
146148
exit 0
147149
}
148150
else
149151
test -f ${APP_RUNTIME}.tar.xz || curl -LSo ${APP_RUNTIME}.tar.xz ${APP_DOWNLOAD_URL}
150152
test -f ${APP_RUNTIME}.tar || xz -d -k ${APP_RUNTIME}.tar.xz
151-
test -f php || tar -xvf ${APP_RUNTIME}.tar
152-
chmod a+x php
153-
cp -f ${__PROJECT__}/var/runtime/php ${__PROJECT__}/bin/runtime/php
153+
test -f php-fpm || tar -xvf ${APP_RUNTIME}.tar
154+
chmod a+x php-fpm
155+
cp -f ${__PROJECT__}/var/runtime/php-fpm ${APP_RUNTIME_DIR}/
156+
mkdir -p ${APP_RUNTIME_DIR}/log
157+
mkdir -p ${APP_RUNTIME_DIR}/run
158+
mkdir -p ${APP_RUNTIME_DIR}/var
154159
fi
155160

156161
cd ${__PROJECT__}/var/runtime
157162

158-
cp -f ${__PROJECT__}/var/runtime/composer.phar ${__PROJECT__}/bin/runtime/composer
159-
cp -f ${__PROJECT__}/var/runtime/cacert.pem ${__PROJECT__}/bin/runtime/cacert.pem
163+
cp -f ${__PROJECT__}/var/runtime/composer.phar ${APP_RUNTIME_DIR}/composer
164+
cp -f ${__PROJECT__}/var/runtime/cacert.pem ${APP_RUNTIME_DIR}/cacert.pem
160165

161-
cat >${__PROJECT__}/bin/runtime/php.ini <<EOF
162-
curl.cainfo="${__PROJECT__}/bin/runtime/cacert.pem"
163-
openssl.cafile="${__PROJECT__}/bin/runtime/cacert.pem"
166+
cat >${APP_RUNTIME_DIR}/php.ini <<EOF
167+
curl.cainfo="${APP_RUNTIME_DIR}/cacert.pem"
168+
openssl.cafile="${APP_RUNTIME_DIR}/cacert.pem"
164169
swoole.use_shortname=off
165170
display_errors = On
166171
error_reporting = E_ALL
@@ -178,7 +183,7 @@ expose_php=Off
178183
179184
EOF
180185

181-
cat >${__PROJECT__}/bin/runtime/php-fpm.conf <<'EOF'
186+
cat >${APP_RUNTIME_DIR}/php-fpm.conf <<'EOF'
182187
; 更多配置参考
183188
; https://github.com/php/php-src/blob/master/sapi/fpm/www.conf.in
184189
; https://github.com/php/php-src/blob/master/sapi/fpm/php-fpm.conf.in
@@ -216,13 +221,70 @@ EOF
216221

217222
cd ${__PROJECT__}/
218223

224+
tee ${APP_RUNTIME_DIR}/start.sh <<'EOF'
225+
#!/usr/bin/env bash
226+
set -exu
227+
__DIR__=$(
228+
cd "$(dirname "$0")"
229+
pwd
230+
)
231+
cd ${__DIR__}
232+
mkdir -p log
233+
mkdir -p run
234+
mkdir -p var
235+
236+
237+
OS=$(uname -s)
238+
if [ "$OS" = 'Darwin' ]; then
239+
# 非 root 设置此项无效
240+
USER=$(whoami)
241+
GROUP=$(groups $(whoami) | cut -d' ' -f1)
242+
# chown -R $(whoami):staff
243+
sed -i.bak "s/user = nobody/user = ${USER}/" php-fpm.conf
244+
sed -i.bak "s/group = nogroup/group = ${GROUP}/" php-fpm.conf
245+
test -f php-fpm.conf.bak && rm -f php-fpm.conf.bak
246+
fi
247+
248+
${__DIR__}/php-fpm -c ${__DIR__}/php.ini --fpm-config ${__DIR__}/php-fpm.conf -p ${__DIR__}/var
249+
250+
EOF
251+
252+
tee ${APP_RUNTIME_DIR}/reload.sh <<'EOF'
253+
#!/usr/bin/env bash
254+
set -exu
255+
__DIR__=$(
256+
cd "$(dirname "$0")"
257+
pwd
258+
)
259+
cd ${__DIR__}
260+
261+
kill -USR2 $(cat ${__DIR__}/var/run/php-fpm.pid)
262+
263+
EOF
264+
265+
tee ${APP_RUNTIME_DIR}/stop.sh <<'EOF'
266+
#!/usr/bin/env bash
267+
set -exu
268+
__DIR__=$(
269+
cd "$(dirname "$0")"
270+
pwd
271+
)
272+
cd ${__DIR__}
273+
274+
kill -QUIT $(cat ${__DIR__}/var/run/php-fpm.pid)
275+
276+
277+
EOF
278+
219279
set +x
220280

221281
echo " "
222282
echo " USE PHP-FPM :"
223283
echo " "
224-
echo " export PATH=\"${__PROJECT__}/runtime/:\$PATH\" "
284+
echo " export PATH=\"${APP_RUNTIME_DIR}/:\$PATH\" "
285+
echo " "
286+
echo " php-fpm.conf example : https://gitee.com/jingjingxyk/quickstart-nginx/blob/main/php-fpm.example.conf"
225287
echo " "
226-
echo " enable start php-fpm ${APP_VERSION}"
288+
echo " start php-fpm ${APP_VERSION}"
227289
echo " "
228-
echo " ${__PROJECT__}/bin/runtime/php-fpm -c ${__PROJECT__}/bin/runtime/php.ini --fpm-config ${__PROJECT__}/runtime/php-fpm.conf "
290+
echo " ${APP_RUNTIME_DIR}/php-fpm -c ${APP_RUNTIME_DIR}/php.ini --fpm-config ${APP_RUNTIME_DIR}/php-fpm.conf "

0 commit comments

Comments
 (0)