-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
php-compiler.sh
696 lines (576 loc) · 27.9 KB
/
php-compiler.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
#!/usr/bin/env bash
#-- Globals
COMPILE_PATH="/usr/local/src/php-build"
CURRENT_PHP_PATH="" # like /opt/php70
CURRENT_PHP_NAME="" # like php70
CURRENT_PHP_VERSION="" # like 70
OUTPUT=""
#-- Helpers Functions
check_return_code() {
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "Error detected in latest command, exiting..."
rm -r "${COMPILE_PATH:?}/php*" 2&> /dev/null
exit 1
fi
}
install_utils() {
echo -e "Installing required packages..."
if [ "${DISTRO}" == "centos7" ]; then
yum -y install epel-release whiptail curl wget ca-certificates
check_return_code
elif [ "${DISTRO}" == "centos8" ]; then
yum -y install epel-release curl wget
check_return_code
else
apt update
check_return_code
apt-get -y install whiptail curl wget
check_return_code
fi
}
check_folder() {
if [ ! -d "${1}" ]; then
echo -e "Creating directory ${1}..."
mkdir -p "${1}"
check_return_code
fi
}
download_extract() {
ARCHIVE_NAME=${1##*/}
FOLDER_NAME=${ARCHIVE_NAME/.tar.gz/}
echo -e "Downloading ${1}..."
wget "${1}" -O "${COMPILE_PATH}/${ARCHIVE_NAME}"
check_return_code
if [ "$(sha256sum "${COMPILE_PATH}/${ARCHIVE_NAME}" | cut -d' ' -f1)" != "${2}" ]; then
echo -e "Checksum mismatch, try to run the script again"
sha256sum "${COMPILE_PATH}/${ARCHIVE_NAME}"; echo
exit 126
else
echo -e "Checksum matched!"
fi
echo -e "Extracting ${ARCHIVE_NAME}..."
tar zxf "${COMPILE_PATH}/${ARCHIVE_NAME}" -C "${COMPILE_PATH}"
check_return_code
}
#-- Install Functions
am_i_root() {
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
}
detect_distro() {
# shellcheck disable=SC1091
source /etc/os-release
check_return_code
DISTRO=""
if echo "${ID}-${VERSION_ID}" | grep -iq "devuan-1"; then
DISTRO=devuan1
fi
if echo "${PRETTY_NAME}" | grep -iq "Devuan GNU/Linux ascii"; then
DISTRO=devuan2
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "debian-3"; then
DISTRO=devuan3
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "debian-8"; then
DISTRO=debian8
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "debian-9"; then
DISTRO=debian9
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "debian-10"; then
DISTRO=debian10
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "debian-11"; then
DISTRO=debian11
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "ubuntu-14.04"; then
DISTRO=ubuntu-14.04
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "ubuntu-16.04"; then
DISTRO=ubuntu-16.04
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "ubuntu-17.04"; then
DISTRO=ubuntu-17.04
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "ubuntu-17.10"; then
DISTRO=ubuntu-17.10
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "ubuntu-18.04"; then
DISTRO=ubuntu-18.04
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "ubuntu-20.04"; then
DISTRO=ubuntu-20.04
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "ubuntu-22.04"; then
DISTRO=ubuntu-22.04
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "centos-7"; then
DISTRO=centos7
fi
if echo "${ID}-${VERSION_ID}" | grep -iq "centos-8"; then
DISTRO=centos8
fi
if [ "${DISTRO}" == "" ]; then
echo "Your distro is not supported"
echo "Your distro: ${ID}-${VERSION_ID}"
echo "You can add it and make a PR ;)"
exit 127
fi
}
install_dependencies() {
if [ "${DISTRO}" == "devuan1" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libjpeg62-turbo-dbg libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libicu-dev libzip-dev pkg-config zlib1g-dev libsqlite3-dev libonig-dev icu-devtools libreadline-dev libgmp-dev
check_return_code
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "devuan2" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libc-client2007e-dev libicu-dev libzip-dev pkg-config zlib1g-dev libsqlite3-dev libonig-dev icu-devtools libreadline-dev libgmp-dev
check_return_code
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "devuan3" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libc-client2007e-dev libicu-dev libzip-dev insserv pkg-config zlib1g-dev libsqlite3-dev libonig-dev icu-devtools libreadline-dev libgmp-dev
check_return_code
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "debian8" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libjpeg62-turbo-dbg libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libicu-dev libzip-dev pkg-config zlib1g-dev libsqlite3-dev libonig-dev icu-devtools libreadline-dev libgmp-dev
check_return_code
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "debian9" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libmcrypt-dev libldb-dev libldap2-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libc-client2007e-dev libicu-dev libzip-dev insserv pkg-config zlib1g-dev libsqlite3-dev libonig-dev icu-devtools libreadline-dev libgmp-dev
check_return_code
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "debian10" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libmcrypt-dev libldb-dev libldap2-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libc-client2007e-dev libicu-dev libzip-dev insserv pkg-config zlib1g-dev libsqlite3-dev libonig-dev icu-devtools libreadline-dev libgmp-dev
check_return_code
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "debian11" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libmcrypt-dev libldb-dev libldap2-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libc-client2007e-dev libicu-dev libzip-dev insserv pkg-config zlib1g-dev libsqlite3-dev libonig-dev icu-devtools libreadline-dev libgmp-dev
check_return_code
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "ubuntu-14.04" ]; then
apt-get -y install build-essential nano wget libjpeg62-dbg libfcgi-dev libfcgi0ldbl libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libicu-dev libzip-dev libreadline-dev libgmp-dev
check_return_code
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "ubuntu-16.04" ]; then
apt-get -y install build-essential nano wget libjpeg62-dbg libfcgi-dev libfcgi0ldbl libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libicu-dev libzip-dev pkg-config zlib1g-dev libsqlite3-dev libonig-dev libreadline-dev libgmp-dev
check_return_code
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "ubuntu-17.04" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libc-client2007e-dev libicu-dev libzip-dev libreadline-dev libgmp-dev
check_return_code
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "ubuntu-17.10" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libc-client2007e-dev libicu-dev libzip-dev libreadline-dev libgmp-dev
check_return_code
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "ubuntu-18.04" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libmcrypt-dev libssl-dev libldb-dev libldap2-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libc-client2007e-dev libicu-dev libzip-dev pkg-config zlib1g-dev libsqlite3-dev libonig-dev icu-devtools libreadline-dev libgmp-dev
check_return_code
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "ubuntu-20.04" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libmcrypt-dev libssl-dev libldb-dev libldap2-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libc-client2007e-dev libicu-dev libzip-dev pkg-config zlib1g-dev libsqlite3-dev libonig-dev icu-devtools libreadline-dev libgmp-dev
check_return_code
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "ubuntu-22.04" ]; then
apt-get -y install build-essential autoconf libfcgi-dev libfcgi0ldbl libmcrypt-dev libssl-dev libldb-dev libldap2-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libwebp-dev libvpx-dev libc-client2007e-dev libicu-dev libzip-dev pkg-config zlib1g-dev libsqlite3-dev libonig-dev icu-devtools libreadline-dev libgmp-dev
check_return_code
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
fi
if [ "${DISTRO}" == "centos7" ]; then
yum -y install gcc make libc-client-devel libxml2-devel pkgconfig openssl-devel bzip2-devel libldb-devel curl-devel libpng-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel httpd-devel postgresql-devel libxslt-devel libwebp-devel libvpx-devel libicu-devel gcc-c++ libzip-devel pkg-config zlib-devel libsqlite3x-devel oniguruma-devel readline-devel
check_return_code
wget http://packages.psychotic.ninja/7/plus/x86_64/RPMS/libzip-0.11.2-6.el7.psychotic.x86_64.rpm -O /tmp/libzip.rpm
check_return_code
wget http://packages.psychotic.ninja/7/plus/x86_64/RPMS/libzip-devel-0.11.2-6.el7.psychotic.x86_64.rpm -O /tmp/libzip-devel.rpm
check_return_code
rpm -Uvh /tmp/libzip.rpm /tmp/libzip-devel.rpm
check_return_code
rm /tmp/libzip.rpm /tmp/libzip-devel.rpm
fi
if [ "${DISTRO}" == "centos8" ]; then
dnf -y install gcc make libc-client-devel libxml2-devel pkgconfig openssl-devel bzip2-devel curl-devel libpng-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel httpd-devel postgresql-devel libxslt-devel libwebp-devel libicu-devel gcc-c++ libzip-devel pkg-config zlib-devel libsqlite3x-devel readline-devel
check_return_code
dnf -y --enablerepo=powertools install oniguruma-devel
check_return_code
fi
}
show_menu() {
menu=()
readarray -t _sorted < <(printf '%s\n' "${!VERSIONS[@]}" | sort)
for version in "${_sorted[@]}"; do
menu+=( "${version}" "" )
done
USER_SELECTION=$(whiptail --title "PHP Compiler" --menu "Install or update:" $((${#menu[@]}+10)) 30 ${#menu[@]} "${menu[@]}" 3>&1 1>&2 2>&3)
}
# $1=php_name (like 'php70'), $2=php_path (like '/opt/php70')
create_init_script() {
cat << "EOF" > "/etc/init.d/${1}-fpm"
#! /bin/sh
### BEGIN INIT INFO
# Provides: &NAME&-fpm
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts &NAME&-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
php_fpm_BIN=&PATH&/sbin/php-fpm
php_fpm_CONF=&PATH&/etc/php-fpm.conf
php_fpm_PID=&PATH&/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
$php_fpm_BIN $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-exit"
exit 1
else
echo " done"
echo " done"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
*)
echo "Usage: $0 {{start|stop|force-quit|restart|reload}}"
exit 1
;;
esac
EOF
sed -i "s:&NAME&:${1}:g" "/etc/init.d/${1}-fpm"
sed -i "s:&PATH&:${2}:g" "/etc/init.d/${1}-fpm"
}
# $1=php_name (like 'php70'), $2=php_path (like '/opt/php70')
create_systemd_script() {
cat << "EOF" > "/lib/systemd/system/${1}-fpm.service"
[Unit]
Description=The &NAME& FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=&PATH&/var/run/php-fpm.pid
ExecStart=&PATH&/sbin/php-fpm --nodaemonize --fpm-config &PATH&/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
EOF
sed -i "s:&NAME&:${1}:g" "/lib/systemd/system/${1}-fpm.service"
sed -i "s:&PATH&:${2}:g" "/lib/systemd/system/${1}-fpm.service"
}
compile_openssl() {
#version="1.1.1q"
#wget "https://www.openssl.org/source/openssl-${version}.tar.gz" -O "/tmp/openssl.tar.gz"
#check_return_code
wget "http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb" -O "/tmp/openssl.deb"
check_return_code
dpkg -i /tmp/openssl.deb
check_return_code
#tar -xzf "/tmp/openssl.tar.gz" -C "/tmp/"
#check_return_code
#(cd "/tmp/openssl-${version}/" && ./Configure --prefix=/tmp/openssl/bin -fPIC -shared linux-x86_64)
#check_return_code
#(cd "/tmp/openssl-${version}/" && make -j 8 )
#check_return_code
#(cd "/tmp/openssl-${version}/" && make install)
#check_return_code
}
compile_freetype() {
version="2.10.1"
wget "https://downloads.sourceforge.net/freetype/freetype-${version}.tar.xz" -O "/tmp/freetype.tar.xz"
check_return_code
tar -xf "/tmp/freetype.tar.xz" -C "/tmp/"
check_return_code
(cd "/tmp/freetype-${version}/" && sed -ri "s:.*(AUX_MODULES.*valid):\1:" modules.cfg)
check_return_code
(cd "/tmp/freetype-${version}/" && sed -r "s:.*(#.*SUBPIXEL_RENDERING) .*:\1:" -i include/freetype/config/ftoption.h)
check_return_code
(cd "/tmp/freetype-${version}/" && ./configure --prefix=/tmp/freetype2/ --enable-freetype-config --disable-static)
check_return_code
make -C "/tmp/freetype-${version}/" -j"${CPU_COUNT}"
check_return_code
make -C "/tmp/freetype-${version}/" install
check_return_code
}
compile() {
ADDITIONAL_CFLAGS="-march=native -mtune=native"
libdir="--with-libdir=/lib/x86_64-linux-gnu"
webp="--with-webp-dir=/usr"
zip="--enable-zip --with-libzip"
freetype="--with-freetype-dir"
gd="--with-gd"
jpg="--with-jpeg-dir=/usr"
openssl="--with-openssl"
ldap="--with-ldap"
if [ "${DISTRO}" == "centos7" ] || [ "${DISTRO}" == "centos8" ]; then
libdir="--with-libdir=lib64"
zip="--enable-zip"
if [ "${CURRENT_PHP_VERSION}" -gt 72 ]; then
ADDITIONAL_CFLAGS=""
fi
fi
if [ "${DISTRO}" == "ubuntu-14.04" ]; then
zip="--enable-zip"
if [ "${CURRENT_PHP_VERSION}" -eq 73 ]; then
zip="--enable-zip --without-libzip"
ADDITIONAL_CFLAGS=""
fi
fi
if [ "${CURRENT_PHP_VERSION}" -lt 70 ]; then
webp="--with-vpx-dir=/usr"
fi
gmp="--with-gmp"
if [ "${DISTRO}" == "ubuntu-16.04" ] && [ "${CURRENT_PHP_VERSION}" -lt 70 ]; then
gmp=""
fi
if { [ "${DISTRO}" == "debian11" ] || [ "${DISTRO}" == "debian10" ] || [ "${DISTRO}" == "devuan3" ] || [ "${DISTRO}" == "ubuntu-20.04" ] || [ "${DISTRO}" == "ubuntu-22.04" ]; } && [ "${CURRENT_PHP_VERSION}" -lt 74 ]; then
compile_freetype
freetype="--with-freetype-dir=/tmp/freetype2"
fi
if [ "${DISTRO}" == "ubuntu-22.04" ]; then
compile_openssl
#openssl="--with-openssl --with-openssl-dir=/tmp/openssl"
openssl="--with-openssl PKG_CONFIG_PATH=/tmp/openssl/bin/lib/pkgconfig"
fi
if [ "${CURRENT_PHP_VERSION}" -gt 73 ]; then
gd="--enable-gd"
freetype="--with-freetype"
jpg="--with-jpeg"
webp="--with-webp"
zip="--with-zip"
fi
# shellcheck disable=SC2086
(cd "${COMPILE_PATH}/${FOLDER_NAME}" && ./configure CFLAGS="-O3 ${ADDITIONAL_CFLAGS}" \
--prefix=${CURRENT_PHP_PATH} --with-pdo-pgsql --with-zlib-dir ${freetype} --enable-mbstring \
--with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-mcrypt \
--with-zlib ${gd} --with-pgsql --disable-rpath --enable-inline-optimization \
--with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm \
--enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash \
${zip} --with-pcre-regex --with-pdo-mysql --with-mysqli --with-mysql-sock=/var/run/mysqld/mysqld.sock \
${jpg} --with-png-dir=/usr ${openssl} --with-fpm-user=www-data \
--with-fpm-group=www-data ${libdir} --enable-ftp --with-imap ${ldap} --with-imap-ssl \
--with-kerberos --with-gettext --with-xmlrpc ${webp} --with-xsl \
--enable-opcache --enable-intl --enable-fpm --with-pear --with-readline ${gmp})
check_return_code
CPU_COUNT=$(grep -c ^processor /proc/cpuinfo)
make -C "${COMPILE_PATH}/${FOLDER_NAME}" -j"${CPU_COUNT}"
check_return_code
if [ -d "${CURRENT_PHP_PATH}" ]; then
echo -e "Stopping services..."
systemctl stop "${CURRENT_PHP_NAME}-fpm.service"
fi
make -C "${COMPILE_PATH}/${FOLDER_NAME}" install
check_return_code
}
install() {
# shellcheck disable=SC2086
if [ -f /.dockerenv ]; then
FPM_PORT=$(shuf -i 2000-50000 -n 1)
if [ "${DISTRO}" == "centos7" ]; then
useradd -M www-data
fi
else
while :; do
FPM_PORT=$(whiptail --title "PHP Compiler" --nocancel --inputbox "Choose the FPM port for ${CURRENT_PHP_NAME}" 10 40 "" 3>&1 1>&2 2>&3)
if [ "$(netstat -tunl | grep -P "^(?=.*LISTEN)(?=.*${FPM_PORT})" -c)" -eq 0 ]; then
break
fi
done
fi
cp "${COMPILE_PATH}/${FOLDER_NAME}/php.ini-production" "${CURRENT_PHP_PATH}/lib/php.ini"
cp "${CURRENT_PHP_PATH}/etc/php-fpm.conf.default" "${CURRENT_PHP_PATH}/etc/php-fpm.conf"
sed -i 's/;pid = run\/php-fpm.pid/pid = run\/php-fpm.pid/' "${CURRENT_PHP_PATH}/etc/php-fpm.conf"
if [ "${CURRENT_PHP_VERSION}" -lt 70 ]; then
sed -i "s/listen = 127.0.0.1:9000/listen = 127.0.0.1:${FPM_PORT}/" "${CURRENT_PHP_PATH}/etc/php-fpm.conf"
echo "include=${CURRENT_PHP_PATH}/etc/php-fpm.d/*.conf" >> "${CURRENT_PHP_PATH}/etc/php-fpm.conf"
check_folder "${CURRENT_PHP_PATH}/etc/php-fpm.d"
else
cp "${CURRENT_PHP_PATH}/etc/php-fpm.d/www.conf.default" "${CURRENT_PHP_PATH}/etc/php-fpm.d/www.conf"
sed -i "s/listen = 127.0.0.1:9000/listen = 127.0.0.1:${FPM_PORT}/" "${CURRENT_PHP_PATH}/etc/php-fpm.d/www.conf"
fi
create_init_script "${CURRENT_PHP_NAME}" "${CURRENT_PHP_PATH}"
chmod 755 "/etc/init.d/${CURRENT_PHP_NAME}-fpm"
insserv "${CURRENT_PHP_NAME}-fpm"
create_systemd_script "${CURRENT_PHP_NAME}" "${CURRENT_PHP_PATH}"
systemctl enable "${CURRENT_PHP_NAME}-fpm.service"
systemctl daemon-reload
echo "zend_extension=opcache.so" >> "${CURRENT_PHP_PATH}/lib/php.ini"
systemctl start "${CURRENT_PHP_NAME}-fpm.service"
}
check_symlink() {
if [ ! -f "/usr/bin/${CURRENT_PHP_NAME}" ]; then
ln -s "${CURRENT_PHP_PATH}/bin/php" "/usr/bin/${CURRENT_PHP_NAME}"
update-alternatives --install /usr/bin/php php "/opt/${CURRENT_PHP_NAME}/bin/php" "${CURRENT_PHP_VERSION}"
fi
}
completed() {
OUTPUT="${OUTPUT}----------- COMPLETED: [${CURRENT_PHP_NAME}] -----------\\n"
OUTPUT="${OUTPUT}FastCGI Settings:\\n"
OUTPUT="${OUTPUT} - Path to the PHP FastCGI binary: ${CURRENT_PHP_PATH}/bin/php-cgi\\n"
OUTPUT="${OUTPUT} - Path to the php.ini directory: ${CURRENT_PHP_PATH}/lib\\n"
OUTPUT="${OUTPUT}PHP-FPM Settings:\\n"
OUTPUT="${OUTPUT} - Path to the PHP-FPM init script: /etc/init.d/${CURRENT_PHP_NAME}-fpm\\n"
OUTPUT="${OUTPUT} - Path to the php.ini directory: ${CURRENT_PHP_PATH}/lib\\n"
OUTPUT="${OUTPUT} - Path to the PHP-FPM pool directory: ${CURRENT_PHP_PATH}/etc/php-fpm.d\\n"
OUTPUT="${OUTPUT}------------------------------------------\\n"
}
cleanup() {
rm -r "${COMPILE_PATH:?}/${FOLDER_NAME}"
rm -r "${COMPILE_PATH:?}/${ARCHIVE_NAME}"
if { [ "${DISTRO}" == "debian11" ] ||[ "${DISTRO}" == "debian10" ] || [ "${DISTRO}" == "devuan3" ] || [ "${DISTRO}" == "ubuntu-20.04" ] || [ "${DISTRO}" == "ubuntu-22.04" ]; } && [ "${CURRENT_PHP_VERSION}" -lt 74 ]; then
rm -r /tmp/freetype-*/
rm -r "/tmp/freetype.tar.xz"
rm -r "/tmp/freetype2/"
fi
if [ "${DISTRO}" == "ubuntu-22.04" ]; then
rm -r /tmp/openssl-*/
fi
}
elaborate_selection() {
if [ "${USER_SELECTION}" == "" ]; then
echo -e "Installation aborted."
exit
fi
escaped_selection="${USER_SELECTION//\"/}"
CURRENT_PHP_NAME="php${escaped_selection:4:1}${escaped_selection:6:1}"
CURRENT_PHP_PATH="/opt/${CURRENT_PHP_NAME}"
CURRENT_PHP_VERSION="${escaped_selection:4:1}${escaped_selection:6:1}"
if { [ "${DISTRO}" == "centos8" ] || [ "${DISTRO}" == "debian9" ] || [ "${DISTRO}" == "debian10" ] || [ "${DISTRO}" == "debian11" ] || [ "${DISTRO}" == "devuan2" ] || [ "${DISTRO}" == "devuan3" ] || [ "${DISTRO}" == "ubuntu-18.04" ] || [ "${DISTRO}" == "ubuntu-20.04" ] || [ "${DISTRO}" == "ubuntu-22.04" ]; } && [ "${CURRENT_PHP_NAME}" == "php56" ]; then
echo -e "Your current distro(${DISTRO}) not support this php version building (${CURRENT_PHP_NAME}). Sorry..."
exit 5
fi
if { [ "${DISTRO}" == "debian11" ] || [ "${DISTRO}" == "debian10" ] || [ "${DISTRO}" == "devuan3" ] || [ "${DISTRO}" == "ubuntu-20.04" ] || [ "${DISTRO}" == "ubuntu-22.04" ]; } && [ "${CURRENT_PHP_NAME}" == "php70" ]; then
echo -e "Your current distro(${DISTRO}) not support this php version building (${CURRENT_PHP_NAME}). Sorry..."
exit 5
fi
echo -e "Checking compile path..."
check_folder "${COMPILE_PATH}"
download_extract "${VERSIONS[$USER_SELECTION]}" "${CHECKSUM[$USER_SELECTION]}"
echo -e "Compiling..."
if [ ! -d "${CURRENT_PHP_PATH}" ]; then
compile
echo -e "First time setup..."
install
else
compile
echo -e "Restarting services..."
systemctl restart "${CURRENT_PHP_NAME}-fpm.service"
fi
check_symlink
completed
cleanup
echo -e "${OUTPUT}"
}
am_i_root
detect_distro
install_utils "$@"
install_dependencies
if [ -f ./versions.sh ]; then
echo "Using local versions.sh"
# shellcheck source=./versions.sh
source ./versions.sh
else
# shellcheck disable=SC1090
source <(curl -s https://raw.githubusercontent.com/SergiX44/ISPC-PHPCompiler/bash-version/versions.sh)
fi
check_return_code
if [ -f /.dockerenv ]; then
USER_SELECTION="${1}"
else
show_menu
fi
elaborate_selection