-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-php-fpm-runtime.sh
228 lines (191 loc) · 5.06 KB
/
setup-php-fpm-runtime.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
set -exu
__DIR__=$(
cd "$(dirname "$0")"
pwd
)
__PROJECT__=${__DIR__}
cd ${__PROJECT__}
OS=$(uname -s)
ARCH=$(uname -m)
case $OS in
'Linux')
OS="linux"
;;
'Darwin')
OS="macos"
;;
*)
case $OS in
'MSYS_NT'*)
OS="windows"
;;
'MINGW64_NT'*)
OS="windows"
;;
*)
echo '暂未配置的 OS '
exit 0
;;
esac
;;
esac
case $ARCH in
'x86_64')
ARCH="x64"
;;
'aarch64' | 'arm64')
ARCH="arm64"
;;
*)
echo '暂未配置的 ARCH '
exit 0
;;
esac
APP_VERSION='v8.2.13'
APP_NAME='php-fpm'
VERSION='php-fpm-v0.0.2'
mkdir -p bin/runtime
mkdir -p var/runtime
MIRROR=''
while [ $# -gt 0 ]; do
case "$1" in
--mirror)
MIRROR="$2"
;;
--proxy)
export HTTP_PROXY="$2"
export HTTPS_PROXY="$2"
NO_PROXY="127.0.0.0/8,10.0.0.0/8,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16"
NO_PROXY="${NO_PROXY},::1/128,fe80::/10,fd00::/8,ff00::/8"
NO_PROXY="${NO_PROXY},localhost"
NO_PROXY="${NO_PROXY},.aliyuncs.com,.aliyun.com,.tencent.com"
NO_PROXY="${NO_PROXY},.myqcloud.com,.swoole.com"
export NO_PROXY="${NO_PROXY},.tsinghua.edu.cn,.ustc.edu.cn,.npmmirror.com"
;;
--version)
# 指定发布 TAG
if [ $OS = "macos" ]; then
X_VERSION=$(echo "$2" | grep -Eo '^v\d\.\d{1,2}\.\d{1,2}$')
elif [ $OS = "linux" ]; then
X_VERSION=$(echo "$2" | grep -Po '^v\d\.\d{1,2}\.\d{1,2}$')
else
X_VERSION=''
fi
if [[ -n $X_VERSION ]]; then
{
VERSION=$X_VERSION
}
fi
;;
--php-version)
# 指定发布 TAG
if [ $OS = "macos" ]; then
X_APP_VERSION=$(echo "$2" | grep -Eo '^v\d\.\d{1,2}\.\d{1,2}$')
elif [ $OS = "linux" ]; then
X_APP_VERSION=$(echo "$2" | grep -Po '^v\d\.\d{1,2}\.\d{1,2}$')
else
X_VERSION=''
fi
if [[ -n $X_APP_VERSION ]]; then
{
APP_VERSION=$X_APP_VERSION
}
fi
;;
--*)
echo "Illegal option $1"
;;
esac
shift $(($# > 0 ? 1 : 0))
done
cd ${__PROJECT__}/var/runtime
APP_DOWNLOAD_URL="https://github.com/swoole/build-static-php/releases/download/${VERSION}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"
COMPOSER_DOWNLOAD_URL="https://getcomposer.org/download/latest-stable/composer.phar"
CACERT_DOWNLOAD_URL="https://curl.se/ca/cacert.pem"
if [ $OS = 'windows' ]; then
APP_DOWNLOAD_URL="https://github.com/swoole/build-static-php/releases/download/${VERSION}/${APP_NAME}-${APP_VERSION}-vs2022-${ARCH}.zip"
fi
case "$MIRROR" in
china)
APP_DOWNLOAD_URL="https://php-cli.jingjingxyk.com/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"
COMPOSER_DOWNLOAD_URL="https://mirrors.tencent.com/composer/composer.phar"
if [ $OS = 'windows' ]; then
APP_DOWNLOAD_URL="https://php-cli.jingjingxyk.com/${APP_NAME}-${APP_VERSION}-cygwin-${ARCH}.zip"
fi
;;
esac
test -f composer.phar || curl -LSo composer.phar ${COMPOSER_DOWNLOAD_URL}
chmod a+x composer.phar
test -f cacert.pem || curl -LSo cacert.pem ${CACERT_DOWNLOAD_URL}
APP_RUNTIME="${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}"
if [ $OS = 'windows' ]; then
{
APP_RUNTIME="${APP_NAME}-${APP_VERSION}-vs2022-${ARCH}"
test -f ${APP_RUNTIME}.zip || curl -LSo ${APP_RUNTIME}.zip ${APP_DOWNLOAD_URL}
test -d ${APP_RUNTIME} && rm -rf ${APP_RUNTIME}
unzip "${APP_RUNTIME}.zip"
echo
exit 0
}
else
test -f ${APP_RUNTIME}.tar.xz || curl -LSo ${APP_RUNTIME}.tar.xz ${APP_DOWNLOAD_URL}
test -f ${APP_RUNTIME}.tar || xz -d -k ${APP_RUNTIME}.tar.xz
test -f php || tar -xvf ${APP_RUNTIME}.tar
chmod a+x php
cp -f ${__PROJECT__}/var/runtime/php ${__PROJECT__}/bin/runtime/php
fi
cd ${__PROJECT__}/var/runtime
cp -f ${__PROJECT__}/var/runtime/composer.phar ${__PROJECT__}/bin/runtime/composer
cp -f ${__PROJECT__}/var/runtime/cacert.pem ${__PROJECT__}/bin/runtime/cacert.pem
cat >${__PROJECT__}/bin/runtime/php.ini <<EOF
curl.cainfo="${__PROJECT__}/bin/runtime/cacert.pem"
openssl.cafile="${__PROJECT__}/bin/runtime/cacert.pem"
swoole.use_shortname=off
display_errors = On
error_reporting = E_ALL
upload_max_filesize="128M"
post_max_size="128M"
memory_limit="1G"
date.timezone="UTC"
opcache.enable_cli=1
opcache.jit=1254
opcache.jit_buffer_size=480M
expose_php=Off
EOF
cat >${__PROJECT__}/bin/runtime/php-fpm.conf <<'EOF'
; 更多配置参考
; https://github.com/php/php-src/blob/master/sapi/fpm/www.conf.in
; https://github.com/php/php-src/blob/master/sapi/fpm/php-fpm.conf.in
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
daemonize = yes
[www]
user = nobody
group = nobody
listen = 9001
;listen = run/php-fpm.sock
slowlog = log/$pool.log.slow
request_slowlog_timeout = 30s
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
; MAIN_PID=$(cat var/run/php-fpm.pid)
; 关闭 php-fpm
; kill -QUIT $MAIN_PID
; 平滑重启 php-fpm
; kill -USR2 $MAIN_PID
EOF
cd ${__PROJECT__}/
set +x
echo " "
echo " USE PHP-FPM :"
echo " "
echo " export PATH=\"${__PROJECT__}/runtime/:\$PATH\" "
echo " "
echo " enable start php-fpm ${APP_VERSION}"
echo " "
echo " ${__PROJECT__}/bin/runtime/php-fpm -c ${__PROJECT__}/bin/runtime/php.ini --fpm-config ${__PROJECT__}/runtime/php-fpm.conf "