This repository has been archived by the owner on May 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
php7.x.y.sh
777 lines (714 loc) · 24.7 KB
/
php7.x.y.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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
#!/bin/bash
# php-7.x.y installer for Trisquel / Ubuntu LTS
# SwITNet Ltd © - 2020, https://switnet.net/
# T&M Hansson IT AB © - 2020, https://www.hanssonit.se/
#
# This script installs the build dependancies for php-7.x.y and looks
# for previous installations it's intended to be used with ISPConfig3.
#
# This program is under the GNU GPLv3 license.
# It is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
while getopts m: option
do
case "${option}"
in
m) MODE=${OPTARG};;
\?) echo "Usage: sudo ./php7.x.y.sh [-m debug]" && exit;;
esac
done
#DEBUG
if [ "$MODE" = "debug" ]; then
set -x
fi
# Reset
Color_Off='\e[0m' # Text Reset
# Regular Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
Cyan='\e[0;36m' # Cyan
clear
printf "${Green}
########################################################################
Welcome to the \"PHP 7.x.y\" compiler
########################################################################
by Software, IT & Networks Ltd
${Color_Off}\n"
install_ifnot() {
if [ "$(dpkg-query -W -f='${Status}' $1 2>/dev/null | grep -c "ok installed")" == "1" ]; then
echo " $1 is installed, skipping..."
else
echo -e "\n---- Installing $1 ----"
apt -yqq install $1
fi
}
#Check if user is root
if ! [ $(id -u) = 0 ]; then
echo "You need to be root or have sudo privileges!"
exit 0
fi
#System requiments
DIST=$(lsb_release -sc)
APACHE_2=$(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed")
NGINX=$(dpkg-query -W -f='${Status}' nginx 2>/dev/null | grep -c "ok installed")
if [ $DIST = flidas ]; then
DIST="xenial"
fi
if [ $DIST = etiona ]; then
DIST="bionic"
fi
if [ "$DIST" = "xenial" ] || [ "$DIST" = "bionic" ]; then
printf "OS: ${Blue} $(lsb_release -sd) ${Color_Off}
Good, this is a supported platform!\n"
else
printf "OS: ${Blue} $(lsb_release -sd) ${Color_Off}
Sorry, this platform is not supported... exiting\n"
exit
fi
check_serv() {
if [ "$APACHE_2" -eq 1 ]; then
WS_IS="apache2"
elif [ "$NGINX" -eq 1 ]; then
WS_IS="nginx"
else
echo \
"We have not identified your webserver you might need to restart it manually."
WS_IS="ukn"
fi
}
apt update -q2
install_ifnot autoconf
install_ifnot build-essential
install_ifnot bison
install_ifnot curl
install_ifnot dialog
install_ifnot nano
install_ifnot re2c
install_ifnot wget
#Selector
check_serv
ws_sites=/etc/${WS_IS}/sites-enabled/
DISCOVER_NC="$(grep -nR 'Dav off\|occ' $ws_sites)"
HEIGHT=15
WIDTH=65
CHOICE_HEIGHT=4
BACKTITLE="PHP 7.x.y selector"
TITLE="Select PHP 7 version to compile."
MENU="
Choose one of the following supported PHP releases:"
MENU2="
What kind of installation would you like to setup:"
OPTIONS=(1 "7.1.X - EOL"
2 "7.2.X"
3 "7.3.X"
4 "7.4.X"
)
OPTIONS_NCSTN=(1 "Hosting Platform (ISPConfig)"
2 "Nextcloud Standalone"
)
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
3>&1 1>&2 2>&3 3>&- )
case $CHOICE in
1)
printf "We'll schedule build of: ${Red} 7.1.X ${Color_Off}\n"
rel="7.1"
;;
2)
printf "We'll schedule build of: ${Green} 7.2.X ${Color_Off}\n"
rel="7.2"
;;
3)
printf "We'll schedule build of: ${Green} 7.3.X ${Color_Off}\n"
rel="7.3"
;;
4)
printf "We'll schedule build of: ${Green} 7.4.X ${Color_Off}\n"
rel="7.4"
;;
*)
printf "Operation canceled, exiting...\n"
exit
;;
esac
if [ "$rel" = "7.3" ] || [ "$rel" = "7.4" ]; then
TITLE2="Select PHP $rel usage to compile."
CHOICE2=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE2" \
--menu "$MENU2" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS_NCSTN[@]}" \
3>&1 1>&2 2>&3 3>&- )
case $CHOICE2 in
1)
printf "We'll schedule build for a ${Blue} Hosting Platform ${Color_Off}\n"
NC_BUILD=no
;;
2)
printf "We'll schedule build for a ${Blue} Nextcloud Standalone ${Color_Off}\n"
NC_BUILD=yes
;;
*)
printf "Operation canceled, exiting...\n"
exit
;;
esac
fi
if [[ $NC_BUILD = yes && -z $DISCOVER_NC ]]; then
echo 'Seems there is no Nextcloud instance running.
Do you wanna continue? (yes o no)'
while [[ $cont_nc != yes && $cont_nc != no ]]
do
read cont_nc
if [ $cont_nc = no ]; then
echo "Ok, come back when you are ready."
exit
elif [ $cont_nc = yes ]; then
echo "Let's get to it ..."
fi
done
fi
dialog --stdout --title "PHP $rel Extension" \
--backtitle "PHP 7" \
--yesno "Do you need support for MaxMind?" 7 60
response=$?
case $response in
0) MXMIND=yes ;;
1) MXMIND=no ;;
255) echo "[ESC] key pressed.";;
esac
dialog --stdout --title "PHP $rel Extension" \
--backtitle "PHP 7" \
--yesno "Do you need support for APCu?" 7 60
response=$?
case $response in
0) APCU=yes ;;
1) APCU=no ;;
255) echo "[ESC] key pressed.";;
esac
# Set variables for standar behavior
php_release=$(curl -s https://www.php.net/downloads.php | grep "php-${rel}" | cut -d\> -f2 | grep ${rel} | head -n1 | cut -d "<" -f1 | awk -F '.tar.bz2' '{print $1}')
# $rel var set by dialog
brel="${rel}.X"
php_path=/opt/php-${brel}
cpv="$php_path/current-php"
libc=/usr/lib/x86_64-linux-gnu/libc-client.a
clibc=/usr/lib/libc-client.a
redis_path=$php_path/phpredis-${brel}
imagick_path=$php_path/imagick-${brel}
memc_path=$php_path/php-memcached-${brel}
mxmd_path=$php_path/php-maxmind-${brel}
apcu_path=$php_path/php-acpu-${brel}
php_bin=$php_path/bin
srv_run="$(ps aux | grep -v color | grep php-fpm | grep php-${brel} | cut -d "(" -f2 | cut -d ")" -f1)"
if [ -s $cpv ]; then
printf "\nCurrent installed php-${brel}: ${Yellow} $(<$cpv)${Color_Off}\n"
printf "Latest php ${brel} release available: ${Green} $php_release ${Color_Off}\n"
else
printf "${Yellow}Seems there is no php-${brel} production installed.${Color_Off}\n"
fi
# Main fork question
if [ -z "$srv_run" ]; then
echo 'Do you wanna continue? (yes o no)'
while [[ $cont != yes && $cont != no ]]
do
read cont
if [ $cont = no ]; then
echo "Ok, come back when you are ready."
exit
elif [ $cont = yes ]; then
mbuild=no
echo "Let's get to it ..."
fi
done
else
printf "\nAlso seems to be a service(s) already running:\n"
printf "${Green}$srv_run ${Color_Off}\n"
printf "\nPlease be advice that overwriting the ${Cyan}php-${brel}${Color_Off} build will set those sites using it ${Yellow}unavailable${Color_Off}!!\n"
echo "Do you wanna overwrite the current php-${brel}? (yes o no)"
while [[ "$cont" != "yes" && "$cont" != "no" ]]
do
read cont
if [ "$cont" = "no" ]; then
printf " --> Do you want compile a maintenance build ( ${Blue}_mbuild ${Color_Off} )? (yes o no)\n"
if [ -f /opt/php-${brel}_mbuild/current-php ]; then
printf " Current ${Cyan}maintenance${Color_Off} buid installed php-${brel}: ${Yellow} $(</opt/php-${brel}_mbuild/current-php)${Color_Off}\n"
else
printf " Seems this will be the first time a ${Cyan}maintenance build${Color_Off} for ${Green}php-${brel}${Color_Off} gets build.\n"
fi
while [[ "$mbuild" != "yes" && "$mbuild" != "no" ]]
do
read mbuild
if [ "$mbuild" = "yes" ]; then
cont="yes"
man_build="_mbuild"
echo "Building php-${brel}_mbuild"
elif [ "$mbuild" = "no" ]; then
echo "No build resolved, see you next time."
exit
exit
fi
done
elif [ "$cont" = "yes" ]; then
echo "Let's get to it ..."
fi
done
fi
#Reset variables after selection.
brel=${rel}.X${man_build}
php_path=/opt/php-${brel}
cpv="$php_path/current-php"
libc=/usr/lib/x86_64-linux-gnu/libc-client.a
clibc=/usr/lib/libc-client.a
redis_path=$php_path/phpredis-${brel}
imagick_path=$php_path/imagick-${brel}
memc_path=$php_path/php-memcached-${brel}
mxmd_path=$php_path/php-maxmind-${brel}
apcu_path=$php_path/php-acpu-${brel}
php_bin=$php_path/bin
runpd=/run/php
printf "${Yellow}# Installing dependencies...${Color_Off}\n"
if [ "$DIST" = "xenial" ]; then
apt -yqq install libfcgi-dev libfcgi0ldbl libjpeg62-dbg libmcrypt-dev \
libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev \
libjpeg-dev libpng12-dev libfreetype6-dev libreadline-dev \
libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libzip-dev libmemcached-dev \
libcurl4-openssl-dev &>/dev/null
fi
if [[ "$DIST" = "xenial" && "$rel" = "7.4" ]]; then
apt -yqq install libsqlite3-dev libonig-dev pkg-config
fi
if [ "$DIST" = "bionic" ]; then
apt -yqq install libfcgi-dev libfcgi0ldbl libjpeg-turbo8-dev libmcrypt-dev \
libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev \
libcurl4-openssl-dev libjpeg-dev libpng-dev libfreetype6-dev libreadline-dev \
libkrb5-dev libpq-dev libxml2-dev libxslt1-dev libzip-dev libsqlite3-dev \
libonig-dev &>/dev/null
fi
if [ -d /usr/include/curl ]; then
echo "CURL symlink in place"
else
echo "Creating CURL symlink"
ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl
fi
if [ -f $libc ]; then
echo "The c-client symbolic link already exists"
else
echo "Creating missing c-client symbolic link"
ln -s $clibc $libc
fi
if [ "$cont" = "yes" ]; then
printf "${Yellow}Removing previous ${brel} release...${Color_Off}\n"
/etc/init.d/php-${brel}-fpm force-quit 2>/dev/null
update-rc.d php-${brel}-fpm disable 2>/dev/null
systemctl stop php-${brel}-fpm 2>/dev/null
systemctl disable php-${brel}-fpm 2>/dev/null
rm -rf /usr/local/src/php5-build/php-${brel} 2>/dev/null
rm -rf $php_path 2>/dev/null
rm -rf /etc/init.d/php-${brel}-fpm 2>/dev/null
rm -rf /usr/local/src/php5-build/php-${brel}.tar.bz2 2>/dev/null
fi
#Build env
mkdir -p $php_path/var/run/php
if [ -d /usr/local/src/php5-build ]; then
echo ""
else
mkdir /usr/local/src/php5-build
fi
cd /usr/local/src/php5-build
#Download
wget --limit-rate=5m -c https://www.php.net/distributions/$php_release.tar.bz2 -O php-${brel}.tar.bz2
tar jxf php-${brel}.tar.bz2
rm -rf php-${brel}.tar.bz2
mv $php_release php-${brel}
cd php-${brel}/
printf "${Yellow}Testing PHP configuration...${Color_Off}\n"
if [[ ${brel} =~ 7.[1-3].* ]]; then
./configure --prefix=$php_path --with-pdo-pgsql --with-zlib-dir \
--with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap \
--enable-calendar --with-curl --with-libzip --with-gd --enable-intl \
--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 --enable-zip \
--with-pcre-regex --with-pdo-mysql --with-mysqli \
--with-mysql-sock=/var/run/mysqld/mysqld.sock --with-jpeg-dir=/usr \
--with-png-dir=/usr --with-openssl --with-readline \
--with-fpm-user=www-data --with-fpm-group=www-data \
--with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-imap \
--with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl \
--enable-opcache --with-pear --enable-fpm | grep "Thank you for using PHP."
fi
if [[ ${brel} =~ 7.4.* ]]; then
./configure --prefix=$php_path --with-pdo-pgsql --with-zlib-dir \
--with-freetype --enable-mbstring --enable-soap --enable-calendar \
--with-curl --with-zlib --enable-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 --with-zip --with-pdo-mysql \
--with-mysqli --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-jpeg \
--with-openssl --with-fpm-user=www-data --with-fpm-group=www-data \
--with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-imap \
--with-imap-ssl --with-readline --with-kerberos --with-gettext \
--with-xmlrpc --with-xsl --enable-opcache --enable-intl --with-pear \
--enable-fpm | grep "Thank you for using PHP."
fi
if [ $? == 0 ]; then
printf "\n${Green}Configuration has succesfully finished, now let's do \`make\`. \
\nThis can take several minutes...${Color_Off}\n"
make -s
else
printf "\n${Red}Configure failed, check log. Exiting...${Color_Off}\n"
exit 1
fi
printf "\n${Yellow}...and finally let us install :) ${Color_Off}\n"
make install
cp /usr/local/src/php5-build/php-${brel}/php.ini-production $php_path/lib/php.ini
cp $php_path/etc/php-fpm.conf.default $php_path/etc/php-fpm.conf
cp $php_path/etc/php-fpm.d/www.conf.default $php_path/etc/php-fpm.d/www.conf
echo $php_release > $php_path/current-php
#SO - PHP - 7.0.X => 9000 - Xenial
#SO - PHP - 7.2.X => 9000 - Bionic
if [ ${brel} = "7.3.X_mbuild" ]; then
sed -i 's|listen = 127.0.0.1:9000|listen = 127.0.0.1:8992|g' $php_path/etc/php-fpm.d/www.conf
UPORT=8995
MPORT=8992
#PHP Build 7.3.X_mbuild => 8992
elif [ ${brel} = "7.2.X_mbuild" ]; then
sed -i 's|listen = 127.0.0.1:9000|listen = 127.0.0.1:8993|g' $php_path/etc/php-fpm.d/www.conf
#PHP Build 7.2.X_mbuild => 8993
elif [ ${brel} = "7.1.X_mbuild" ]; then
sed -i 's|listen = 127.0.0.1:9000|listen = 127.0.0.1:8994|g' $php_path/etc/php-fpm.d/www.conf
#PHP Build 7.1.X_mbuild => 8994
elif [ ${brel} = "7.3.X" ] && [ ${NC_BUILD} = "yes" ]; then
sed -i 's|listen = 127.0.0.1:9000|listen = 127.0.0.1:8995|g' $php_path/etc/php-fpm.d/www.conf
UPORT=8995
MPORT=8992
#PHP Build 7.3.X => 8995
elif [ ${brel} = "7.3.X" ]; then
sed -i 's|listen = 127.0.0.1:9000|listen = 127.0.0.1:8996|g' $php_path/etc/php-fpm.d/www.conf
#PHP Build 7.3.X => 8996
elif [ ${brel} = "7.2.X" ]; then
sed -i 's|listen = 127.0.0.1:9000|listen = 127.0.0.1:8997|g' $php_path/etc/php-fpm.d/www.conf
#PHP Build 7.2.X => 8997
elif [ ${brel} = "7.1.X" ]; then
sed -i 's|listen = 127.0.0.1:9000|listen = 127.0.0.1:8998|g' $php_path/etc/php-fpm.d/www.conf
#PHP Build 7.1.X => 8998
##PHP Build 5.6.X => 8999 - Deprecated # Reusing for PHP 7.4
elif [ ${brel} = "7.4.X_mbuild" ]; then
sed -i 's|listen = 127.0.0.1:9000|listen = 127.0.0.1:8991|g' $php_path/etc/php-fpm.d/www.conf
UPORT=8999
MPORT=8991
#PHP Build 7.4.X_mbuild => 8991
elif [ ${brel} = "7.4.X" ]; then
sed -i 's|listen = 127.0.0.1:9000|listen = 127.0.0.1:8999|g' $php_path/etc/php-fpm.d/www.conf
UPORT=8999
MPORT=8991
#PHP Build 7.4.X => 8999
else
echo "No compatible version exiting.."
echo "Please report any issue to: https://switnet.net"
#exit
fi
sed -i "s|;pid = run/php-fpm.pid|pid = run/php/php-fpm-${brel}.pid|g" $php_path/etc/php-fpm.conf
sed -i "s|;include=etc/fpm.d/\*.conf|include=/opt/php-${brel}/etc/php-fpm.d/\*.conf|g" $php_path/etc/php-fpm.conf
sed -i "s|memory_limit = 128M|memory_limit = 256M|" $php_path/lib/php.ini
kill $(ps aux | grep "[p]hp${brel}-fpm.conf" | awk '{print $2}')
cat << SYSTEMD > /lib/systemd/system/php-${brel}-fpm.service
[Unit]
Description=The PHP ${brel} FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=$php_path/var/run/php-fpm.pid
ExecStart=$php_path/sbin/php-fpm --nodaemonize --fpm-config $php_path/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 \$MAINPID
[Install]
WantedBy=multi-user.target
SYSTEMD
chmod 755 /lib/systemd/system/php-${brel}-fpm.service
systemctl enable php-${brel}-fpm.service
systemctl start php-${brel}-fpm.service
#Redis
printf "\n${Yellow}Adding Redis Support${Color_Off}\n
Deleting previous builds"
rm -rf $redis_path
install_ifnot redis-server
git clone -b develop https://github.com/phpredis/phpredis.git $redis_path
cd $redis_path ; $php_bin/phpize
PATH=$php_bin:$PATH ./configure -q
make -s
make install
cat << PHP_RS >> $php_path/lib/php.ini
;;; Redis ;;;
extension=redis.so
;;; OPCache ;;;
zend_extension=opcache.so
PHP_RS
#IMagick
printf "\n${Yellow}Adding IMagick Support${Color_Off}\n
Deleting previous builds"
rm -rf $imagick_path
install_ifnot libmagickwand-dev
git clone -b master https://github.com/mkoppanen/imagick.git $imagick_path
cd $imagick_path ; $php_bin/phpize
PATH=$php_bin:$PATH ./configure -q
make -s
make install
echo \
';;; Imagick ;;;
extension=imagick.so' >> $php_path/lib/php.ini
# Memcache
printf "\n${Yellow}Adding IMagick Support${Color_Off}\n
Deleting previous builds"
rm -rf $memc_path
install_ifnot libmemcached-dev
git clone -b master https://github.com/php-memcached-dev/php-memcached $memc_path
cd $memc_path ; $php_bin/phpize
PATH=$php_bin:$PATH ./configure --with-php-config=$php_bin/php-config -q
make -s
make install
echo \
';;; Memcached ;;;
extension=memcached.so' >> $php_path/lib/php.ini
if [ "$APCU" = "yes" ]; then
# APCu
printf "\n${Yellow}Adding ACPU Support${Color_Off}\n
Deleting previous builds"
rm -rf $apcu_path
git clone -b master https://github.com/krakjoe/apcu $apcu_path
cd $apcu_path ; $php_bin/phpize
PATH=$php_bin:$PATH ./configure --with-php-config=$php_bin/php-config -q
make -s
make install
cat << PHP_AU >> $php_path/lib/php.ini
;;; APCu ;;;
extension=apcu.so
apc.enabled=1
apc.enable_cli=1
apc.shm_size=128M
apc.ttl=7200
PHP_AU
fi
# -xDebug
#cd /opt/php-7.3.X/etc
#pecl -C ./pear.conf update-channels
#pecl -C ./pear.conf install xdebug
#echo "zend_extension=/opt/php-7.3.X/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so" | tee -a /opt/php-7.3.X/lib/php.ini
if [ "$MXMIND" = "yes" ]; then
# -MaxMind
install_ifnot libmaxminddb-dev
git clone https://github.com/maxmind/MaxMind-DB-Reader-php $mxmd_path
cd $mxmd_path/ext ; $php_bin/phpize
PATH=$php_bin:$PATH ./configure --with-php-config=$php_bin/php-config -q
make -s
make install
echo \
';;; MaxmindDB ;;;
extension=maxminddb.so' >> $php_path/lib/php.ini
fi
cd $php_bin
printf "\n${Blue}$(./php -v)${Color_Off}\n"
printf "${Red}$(./php --ri redis | head -n 7)${Color_Off}\n"
printf "${Yellow}$(./php --ri imagick | head -n 10)${Color_Off}\n"
printf "${Green}$(./php --ri memcached | head -n 6)${Color_Off}\n"
if [ "$APCU" = "yes" ]; then
printf "${Blue}$(./php --ri apcu | head -n 6)${Color_Off}\n"
fi
if [ "$MXMIND" = "yes" ]; then
printf "${Purple}$(./php --ri maxminddb | head -n 6)${Color_Off}\n"
fi
service php-${brel}-fpm restart
if [ ! $WS_IS = "ukn" ];then
service $WS_IS restart
fi
########################################################################
# Nextcloud configuration #
########################################################################
if [ "${NC_BUILD}" = "yes" ]; then
dialog --title "PHP ${brel} services active" --msgbox \
"$(netstat -lp | \
grep 899 | awk '{print $4}'| \
sed -e "s|localhost:899[1,2]|php-${brel} - Maintenance Build|" \
-e "s|localhost:899[5,9]|php-${brel} - Production Build|")" \
7 50
#printf "${Cyan}$(netstat -lp | grep 899 | awk '{print $4}'| \
# sed -e "s|localhost:8992|php-7.3.X_mbuild - Maintenance Build|" -e \
# "s|localhost:8995|php-7.3.X - Production Build|")${Color_Off}\n"
#Selector
#HEIGHT=15
#WIDTH=65
#CHOICE_HEIGHT=4
#BACKTITLE="PHP ${brel} - Nextcloud"
#TITLE="PHP 7 - Selector"
#MENU="
#Select the PHP 7 you have previously build to use Nextcloud:"
#
#OPTIONS=(1 "7.3.X (Production)"
# 2 "7.3.X_mbuild (Maintenance)"
# )
#
#CHOICE=$(dialog --clear \
# --backtitle "$BACKTITLE" \
# --title "$TITLE" \
# --menu "$MENU" \
# $HEIGHT $WIDTH $CHOICE_HEIGHT \
# "${OPTIONS[@]}" \
# 3>&1 1>&2 2>&3 3>&- )
#case $CHOICE in
# 1)
# printf "We'll schedule setup of: ${Green} 7.3.X ${Color_Off}\n"
# nrel="7.3.X"
# ;;
# 2)
# printf "We'll schedule setup of: ${Green} 7.3.X_mbuild ${Color_Off}\n"
# nrel="7.3.X_mbuild"
# ;;
# *)
# printf "Operation canceled, exiting...\n"
# exit
# ;;
#esac
PHP_POOL_DIR=/opt/php-${brel}/etc/php-fpm.d
PHP_INI=/opt/php-${brel}/lib/php.ini
NC_SYSTEM_FILE=/lib/systemd/system/nc_php-${brel}-fpm.service
if [ ! -d $runpd ];then
mkdir $runpd
fi
average_php_memory_requirement=50
available_memory=$(awk '/MemAvailable/ {printf "%d", $2/1024}' /proc/meminfo)
PHP_FPM_MAX_CHILDREN=$((available_memory/average_php_memory_requirement))
calculate_max_children() {
# Calculate max_children depending on RAM
# Tends to be between 30-50MB
printf "${Cyan}Automatically configures pm.max_children for php-fpm...${Color_Off}\n"
if [ $PHP_FPM_MAX_CHILDREN -lt 8 ]
then
msg_box "The current max_children value available to set is $PHP_FPM_MAX_CHILDREN, and with that value PHP-FPM won't function properly.
The minimum value is 8, and the value is calculated depening on how much RAM you have left to use in the system."
exit 1
else
printf "${Green}pm.max_children was set to $PHP_FPM_MAX_CHILDREN${Color_Off}\n"
fi
}
calculate_max_children
systemctl stop php-${brel}-fpm.service
systemctl disable php-${brel}-fpm.service
if [ WS_IS = "apache2" ]; then
a2enmod proxy proxy_fcgi
fi
# Set up a php-fpm pool with a unixsocket
cat << POOL_CONF > "$PHP_POOL_DIR/nextcloud_${brel}.conf"
[Nextcloud ${brel} ]
user = www-data
group = www-data
listen = 127.0.0.1:$UPORT
listen.owner = www-data
listen.group = www-data
pm = dynamic
;; max_children is set dynamically with calculate_max_children()
pm.max_children = $PHP_FPM_MAX_CHILDREN
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 3
pm.max_requests = 500
env[HOSTNAME] = $(hostname -f)
env[PATH] = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
security.limit_extensions = .php
php_admin_value [cgi.fix_pathinfo] = 1
POOL_CONF
cat << NC_PHP >> "$PHP_INI"
; Nextcloud custom php configurations
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
NC_PHP
# Update Nextcloud limits
sed -i "s|memory_limit = .*|memory_limit = 512M|" $PHP_INI
sed -i "s|upload_max_filesize = .*|upload_max_filesize = 1024M|" $PHP_INI
cat << NC_SYSTEM_PHP > "$NC_SYSTEM_FILE"
[Unit]
Description=The PHP 7.3 FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/opt/php-${brel}/var/run/nc_php-fpm_${brel}.pid
ExecStart=/opt/php-${brel}/sbin/php-fpm --nodaemonize --fpm-config $PHP_POOL_DIR/nextcloud_${brel}.conf
ExecReload=/bin/kill -USR2 \$MAINPID
[Install]
WantedBy=multi-user.target
NC_SYSTEM_PHP
chmod 755 /lib/systemd/system/nc_php-${brel}-fpm.service
systemctl enable nc_php-${brel}-fpm.service
systemctl start nc_php-${brel}-fpm.service
##Set Apache2 file
echo "We have found the following Nextcloud instances using PHP $rel:"
NC_INST="$(grep -r "Dav off" /etc/apache2/sites-enabled/* | cut -d ":" -f1 | xargs -L1 grep -le 8995 -le 8992 -le 8991 -le 8999)"
NX_NC_INST="$(grep -r "occ" /etc/nginx/sites-enabled/* | cut -d ":" -f1 | xargs -L1 grep -le 8995 -le 8992 -le 8991 -le 8999)"
if [ $WS_IS = "apache2" ];then
printf "${Green}$NC_INST${Color_Off}\n"
elif [ $WS_IS = "nginx" ];then
printf "${Green}$NX_NC_INST${Color_Off}\n"
else
echo "We can't determine your web server please make adjustmenst manually."
fi
if [[ ${brel} = 7.3.X ]] || [[ ${brel} = 7.4.X ]]; then
if [ $WS_IS = "apache2" ]; then
grep -r "Dav off" /etc/${WS_IS}/sites-enabled/* | cut -d ":" -f1 | xargs -L1 sed -i "s|127.0.0.1:.*|127.0.0.1:$UPORT|"
elif [ $WS_IS = "nginx" ]; then
grep -r "occ" /etc/${WS_IS}/sites-enabled/* | cut -d ":" -f1 | xargs -L1 sed -i "s|127.0.0.1:.*|127.0.0.1:$UPORT;|"
fi
sed -i "s|127.0.0.1:.*|127.0.0.1:$UPORT|" $PHP_POOL_DIR/nextcloud_${brel}.conf
elif [[ ${brel} = 7.3.X_mbuild ]] || [[ ${brel} = 7.4.X_mbuild ]]; then
if [ $WS_IS = "apache2" ]; then
grep -r "Dav off" /etc/${WS_IS}/sites-enabled/* | cut -d ":" -f1 | xargs -L1 sed -i "s|127.0.0.1:.*|127.0.0.1:$MPORT|"
elif [ $WS_IS = "nginx" ]; then
grep -r "occ" /etc/${WS_IS}/sites-enabled/* | cut -d ":" -f1 | xargs -L1 sed -i "s|127.0.0.1:.*|127.0.0.1:$MPORT;|"
fi
sed -i "s|127.0.0.1:.*|127.0.0.1:$MPORT|" $PHP_POOL_DIR/nextcloud_${brel}.conf
else
echo "Error configuring ${WS_IS}, please report it."
fi
service nc_php-${brel}-fpm restart
if [ ! $WS_IS = "ukn" ];then
service $WS_IS restart
fi
fi
echo "Creating symlinks..."
create_symlink() {
if [ -f $1 ]; then
ln -s $1 $2
fi
}
pbin=$(echo ${brel} | awk '{print tolower($0)}' | sed 's|[^[:alnum:]/]\+||g' | sed 's|build||')
if [ -z $pbin ]; then
echo "Seems there is an issue with symlink variable, skiping for now..."
else
rm -rf /usr/bin/php${pbin}
create_symlink /opt/php-${brel}/bin/php /usr/bin/php${pbin}
ls -l /usr/bin/php${pbin}
fi
#Remove build info
rm -rf /usr/local/src/php5-build/php-${brel} 2>/dev/null
printf "${Blue}
########################################################################
Installation complete!!
for customized support: http://switnet.net
########################################################################
${Color_Off}\n"