/
php_upgrade.inc
556 lines (441 loc) · 17 KB
/
php_upgrade.inc
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
########################################################################
autodetectextensions() {
if [ -f ${CONFIGSCANDIR}/xcache.ini ]; then
DETECTXCACHE=y
fi
if [ -f ${CONFIGSCANDIR}/apc.ini ]; then
DETECTAPC=y
fi
if [ -f ${CONFIGSCANDIR}/igbinary.ini ]; then
if [[ "$PHPMUVER" != 'NGDEBUG' ]]; then
DETECTIGBINARY=y
else
# remove igbinary.ini when PHP NGDEBUG detected on upgrade
DETECTIGBINARY=n
echo "rm -rf ${CONFIGSCANDIR}/igbinary.ini"
rm -rf ${CONFIGSCANDIR}/igbinary.ini
fi
fi
if [[ -f ${CONFIGSCANDIR}/memcache.ini || -f ${CONFIGSCANDIR}/memcached.ini ]]; then
if [[ "$PHPMUVER" != 'NGDEBUG' ]]; then
DETECTMEMCACHED=y
else
# remove memcache.ini & memcached.ini when PHP NGDEBUG detected on upgrade
DETECTMEMCACHED=n
echo "rm -rf ${CONFIGSCANDIR}/memcache.ini"
# echo "rm -rf ${CONFIGSCANDIR}/memcached.ini"
rm -rf ${CONFIGSCANDIR}/memcache.ini
# rm -rf ${CONFIGSCANDIR}/memcached.ini
fi
fi
if [[ -f "${CONFIGSCANDIR}/redis.ini" || "$PHPREDIS" = [yY] ]]; then
DETECTREDIS=y
fi
if [[ -f "${CONFIGSCANDIR}/mongodb.ini" || "$PHPMONGODB" = [yY] ]]; then
DETECTMONGODB=y
fi
if [ -f ${CONFIGSCANDIR}/zendopcache.ini ]; then
DETECTOPCACHE=y
fi
if [ -f ${CONFIGSCANDIR}/imagick.ini ]; then
if [[ "$PHPMUVER" != 'NGDEBUG' ]]; then
DETECTIMAGICK=y
else
# remove imagick.ini when PHP NGDEBUG detected on upgrade
DETECTIMAGICK=n
echo "rm -rf ${CONFIGSCANDIR}/imagick.ini"
rm -rf ${CONFIGSCANDIR}/imagick.ini
fi
if [[ "$PHPIMAGICK" != [yY] ]]; then
echo "rm -rf ${CONFIGSCANDIR}/imagick.ini"
rm -rf ${CONFIGSCANDIR}/imagick.ini
fi
fi
if [ -f ${CONFIGSCANDIR}/geoip.ini ]; then
DETECTGEOIP=y
else
DETECTGEOIP=y
fi
}
########################################################################
autodetectinstallextensions() {
cecho "----------------------------------------------------" $boldgreen
cecho "Auto reinstalling previously detected PHP extensions" $boldyellow
cecho "----------------------------------------------------" $boldgreen
if [[ "$DETECTXCACHE" = [yY] ]]; then
cecho "Auto reinstalling previously detected Xcache" $boldyellow
funct_xcachereinstall
fi
if [[ "$DETECTAPC" = [yY] ]]; then
cecho "Auto reinstalling previously detected APC Cache" $boldyellow
funct_apcreinstall
fi
if [[ "$DETECTIGBINARY" = [yY] ]]; then
cecho "Auto reinstalling previously detected igbinary extension" $boldyellow
funct_igbinaryinstall
fi
if [[ "$DETECTMEMCACHED" = [yY] ]]; then
cecho "Auto reinstalling previously detected memcached/memcache php extension" $boldyellow
funct_memcachedreinstall
fi
if [[ "$DETECTREDIS" = [yY] ]]; then
cecho "Auto reinstalling previously detected redis PHP extension" $boldyellow
redisinstall
fi
if [[ "$DETECTMONGODB" = [yY] ]]; then
cecho "Auto reinstalling previously detected MongoDB PHP extension" $boldyellow
mongodbinstall
fi
if [[ "$DETECTOPCACHE" = [yY] ]]; then
if [[ "$PHPMUVER" != '5.5' || "$PHPMUVER" != '5.6' || "$PHPMUVER" != '5.7' || "$PHPMUVER" != '7.0' ]]; then
cecho "Auto reinstalling previously detected Zend Opcache" $boldyellow
zopcachereinstall
elif [[ "$PHPMUVER" = '5.5' || "$PHPMUVER" = '5.6' || "$PHPMUVER" = '5.7' || "$PHPMUVER" = '7.0' ]] && [[ "$ZOPCACHE_OVERRIDE" = [yY] ]]; then
# ZOPCACHE_OVERRIDE=y allows you to override PHP 5.5-7.0's inbuilt included
# Zend Opcache version with one available from pecl site
cecho "Auto reinstalling previously detected Zend Opcache" $boldyellow
zopcachereinstall
fi
fi
if [[ "$DETECTIMAGICK" = [yY] ]]; then
cecho "Auto reinstalling previously detected imagemagick extension" $boldyellow
imagickinstall
fi
if [[ "$DETECTGEOIP" = [yY] ]]; then
cecho "Auto reinstalling previously detected geoip extension" $boldyellow
geoipphpext
fi
# Fix extension directory on major PHP version changes
# Zend Opcache related when downgrading PHP major versions
PHPEXTDIRDNEW=`cat /usr/local/bin/php-config | awk '/^extension_dir/ {extdir=$1} END {gsub(/\047|extension_dir|=|)/,"",extdir); print extdir}'`
OLD=$(echo $PHPEXTDIRDOLD | sed 's/\//\\\//g')
NEW=$(echo $PHPEXTDIRDNEW | sed 's/\//\\\//g')
for ini in $(ls ${CONFIGSCANDIR}/ | grep .ini)
do
echo $ini
sed -i "s/$OLD/$NEW/g" ${CONFIGSCANDIR}/${ini} 2>&1>/dev/null
done
}
########################################################################
funct_phpupgrade() {
if [ ${MACHINE_TYPE} == 'x86_64' ];
then
ARCH='x86_64'
else
ARCH='i386'
fi
# Set LIBDIR
if [ ${ARCH} == 'x86_64' ];
then
LIBDIR='lib64'
else
LIBDIR='lib'
fi
echo " "
if [[ "$UALL" = 'y' ]]; then
key='y'
else
read -ep "PHP Upgrade - Would you like to continue? [y/n] " key
if [[ "$key" = [nN] ]];
then
exit 0
fi
fi # UALL
DIR_TMP="$DIR_TMP"
if [ ! -d "$DIR_TMP" ]; then
mkdir $DIR_TMP
fi
funct_mktempfile
if [[ "$UALL" = 'y' ]]; then
phpver=${PHP_VERSION}
overwritephpfpmconf='n'
lessphpmem='y'
else
echo "----------------------------------------------------------------"
echo "Install which version of PHP? (version i.e. ${PHP_VERSION}, 7.0.0, NGDEBUG)"
echo "PHP 7.0.0 is GA Stable but still may have broken PHP extensions."
echo "NGDEBUG is PHP 7.1.0 minus incompatible PHP extensions"
echo "----------------------------------------------------------------"
read -ep "Enter PHP Version number you want to upgrade/downgrade to: " phpver
echo "----------------------------------------------------------------"
echo "existing php.ini will be backed up at /usr/local/lib/php.ini-oldversion_$DT"
# only prompt for php-fpm.conf overwrite if the existing /usr/local/nginx/conf/php.conf file
# differs from the current centmin mod template file
if [[ -f /usr/local/nginx/conf/php.conf && -f "$CUR_DIR/config/nginx/php.conf" ]]; then
diff -u /usr/local/nginx/conf/php.conf $CUR_DIR/config/nginx/php.conf &>/dev/null
PHPCONF_DIFFCHECK=$?
else
PHPCONF_DIFFCHECK=1
fi
if [[ "$PHPCONF_DIFFCHECK" != '0' ]]; then
echo "Want to update to latest php-fpm.conf ? (overwrites will auto backup existing php-fpm.conf)"
echo "existing php-fpm.conf will be backed up at /usr/local/etc/php-fpm.conf-oldversion_$DT"
echo "----------------------------------------------------------------"
read -ep "Update & overwrite your existing php-fpm.conf [y/n]: " overwritephpfpmconf
echo "----------------------------------------------------------------"
else
echo "----------------------------------------------------------------"
overwritephpfpmconf=n
fi
# switch to auto calculate system memory instead of prompting for user input
IS_PHPLOWMEM='2097152'
CHECK_PHPLOWMEM=`expr $TOTALMEM \< $IS_PHPLOWMEM`
if [ "$CHECK_PHPLOWMEM" == "1" ]; then
lessphpmem=y
fi
fi # UALL
## grab newer custom written htpasswd.sh as well
gethtpasswdsh
PHPCURRENTVER=$(php -v | awk -F " " '{print $2}' | head -n1 | cut -d . -f1,2)
PHPMUVER=$(echo "$phpver" | cut -d . -f1,2)
PHPMU_ALPHAVER=$(echo "$phpver")
phpng_download
autodetectextensions
zopcacheupgrade
echo "*************************************************"
cecho "* Upgrading PHP" $boldgreen
echo "*************************************************"
funct_centos6check
export PHP_AUTOCONF=/usr/bin/autoconf
export PHP_AUTOHEADER=/usr/bin/autoheader
cd $DIR_TMP
if [ "$(rpm -qa | grep '^php*')" ]; then
# IMPORTANT Erase any PHP installations first, otherwise conflicts may arise
echo "yum -y erase php*"
yum -y erase php*
fi
if [[ "$CENTOSVER" = '6.0' || "$CENTOSVER" = '6.1' || "$CENTOSVER" = '6.2' || "$CENTOSVER" = '6.3' || "$CENTOSVER" = '6.4' || "$CENTOSVER" = '6.5' || "$CENTOSVER" = '6.6' || "$CENTOSVER" = '6.7' || "$CENTOSVER" = '6.8' || "$CENTOSVER" = '6.9' || "$CENTOSVER" = '7.0' || "$CENTOSVER" = '7.1' || "$CENTOSVER" = '7.2' || "$CENTOSVER" = '7.3' || "$CENTOSVER" = '7.4' || "$CENTOSVER" = '7.5' || "$CENTOSVER" = '7.6' || "$CENTOSVER" = '7.7' ]]; then
DOWNLOADAPP="wget ${WGETOPT} --progress=bar"
WGETRETRY='--tries=3'
AXELPHPTARGZ="-O php-${PHP_VERSION}.tar.gz"
AXELPHPUPGRADETARGZ="-O php-${phpver}.tar.gz"
else
DOWNLOADAPP="wget ${WGETOPT} --progress=bar"
WGETRETRY='--tries=3'
AXELPHPTARGZ=''
AXELPHPUPGRADETARGZ=''
fi
if [ -s php-${phpver}.tar.gz ]; then
cecho "php ${phpver} Archive found, skipping download..." $boldgreen
else
$DOWNLOADAPP ${PHP_MIRRORURL}/get/php-${phpver}.tar.gz/from/this/mirror $AXELPHPUPGRADETARGZ $WGETRETRY
fi
tar xzvf php-${phpver}.tar.gz
cd php-${phpver}
##############################################
# begin update php.ini
echo ""
echo "*************************************************"
cecho "* Updating php.ini... " $boldgreen
echo "*************************************************"
echo "old php.ini will be saved at /usr/local/lib/php.ini-oldversion_$DT"
echo "if you have modified your old php.ini i.e. installed and loaded"
echo "APC, Xcache, Memcache or Suhosin - please re-install them after php upgrade"
echo "..."
cp -f /usr/local/lib/php.ini /usr/local/lib/php.ini-oldversion_$DT
cp -f php.ini-production /usr/local/lib/php.ini
chmod 644 /usr/local/lib/php.ini
phpsededit
PHPDIFF=`diff /usr/local/lib/php.ini /usr/local/lib/php.ini-oldversion_$DT`
echo ""
if [ ! -z "$PHPDIFF" ]; then
echo "checking updated php.ini compared to old /usr/local/lib/php.ini-oldversion_$DT"
echo "please note the following differences: "
echo "if APC, Xcache, Memcache, Suhosin or FFMPEG Extensions are listed please re-install them"
echo ""
echo "--------------------------------------------------------------------------------------------"
diff /usr/local/lib/php.ini /usr/local/lib/php.ini-oldversion_$DT
echo "--------------------------------------------------------------------------------------------"
echo ""
echo "*************************************************"
echo "Automatically continuing upgrade in 6 seconds..."
echo "*************************************************"
sleep 6
echo ""
fi # PHPDIFF
# end update php.ini
##############################################
make clean
./buildconf --force
if [ ! -d fpm-build ]; then
mkdir fpm-build
fi
cd fpm-build
make clean
#mkdir -p /usr/${LIBDIR}/mysql
#ln -s /usr/${LIBDIR}/libmysqlclient.so /usr/${LIBDIR}/mysql/libmysqlclient.so
funct_phpconfigure
################
# error check
ERR=$?
if [ $ERR != 0 ]; then
echo -e "\n`date`\nError: $ERR, PHP configure failed ($SCRIPT_VERSION)\n"
exit
else
echo -e "\n`date`\nSuccess: PHP configure ok\n"
cmservice php-fpm restart
fi
# error check
################
echo "make${MAKETHREADS}"
time make${MAKETHREADS}
################
# error check
ERR=$?
if [ $ERR != 0 ]; then
echo -e "\n`date`\nError: $ERR, PHP make failed ($SCRIPT_VERSION)\n"
exit
else
echo -e "\n`date`\nSuccess: PHP make ok\n"
cmservice php-fpm restart
fi
# error check
################
echo "make install"
time make install
if [[ "$STRIPPHP" = [yY] ]]; then
echo
echo "strip PHP binary..."
ls -lah /usr/local/bin/php
ls -lah /usr/local/bin/php-cgi
strip -s /usr/local/bin/php
strip -s /usr/local/bin/php-cgi
ls -lah /usr/local/bin/php
ls -lah /usr/local/bin/php-cgi
echo
fi
################
# error check
ERR=$?
if [ $ERR != 0 ]; then
echo -e "\n`date`\nError: $ERR, PHP wasn't installed properly ($SCRIPT_VERSION)\n"
exit
else
echo -e "\n`date`\nSuccess: PHP was installed properly\n"
echo
echo
# read -ep "Do you want to update to latest php-fpm.conf ? It will overwrite your existing php-fpm.conf [y/n]: " overwritephpfpmconf
if [[ "$overwritephpfpmconf" = [yY] ]]; then
# read -ep "Does this server have less than <=2048MB of memory installed ? [y/n]: " lessphpmem
echo
echo "Backing up existing php-fpm.conf at /usr/local/etc/php-fpm.conf-oldversion_$DT"
echo "If you have made an custom changes to /usr/local/etc/php-fpm.conf, you will find"
echo "they still exist in backup at /usr/local/etc/php-fpm.conf-oldversion_$DT"
cp -f /usr/local/etc/php-fpm.conf /usr/local/etc/php-fpm.conf-oldversion_$DT
ls -lhrt /usr/local/etc/ | grep php-fpm.conf
sleep 9
echo
echo "Backing up existing php.conf at /usr/local/nginx/conf/php.conf-oldversion_$DT"
echo "If you have made an custom changes to /usr/local/nginx/conf/php.conf, you will find"
echo "they still exist in backup at /usr/local/nginx/conf/php.conf-oldversion_$DT"
cp -f /usr/local/nginx/conf/php.conf /usr/local/nginx/conf/php.conf-oldversion_$DT
ls -lhrt /usr/local/nginx/conf/ | grep php.conf
cp -f $CUR_DIR/config/nginx/php.conf /usr/local/nginx/conf/php.conf
# recheck whether fastcgi_param GEOIP_ settings in php.conf need to be disabled or enabled
if [[ "$NGINX_GEOIP" = [yY] ]]; then
sed -i 's/#fastcgi_param GEOIP_/fastcgi_param GEOIP_/' /usr/local/nginx/conf/php.conf
else
sed -i 's/fastcgi_param GEOIP_/#fastcgi_param GEOIP_/' /usr/local/nginx/conf/php.conf
fi
sleep 12
echo
if [[ "$lessphpmem" = [yY] ]]; then
echo $lessphpmem
echo -e "\nCopying php-fpm-min.conf /usr/local/etc/php-fpm.conf\n"
cp -f $CUR_DIR/config/php-fpm/php-fpm-min.conf /usr/local/etc/php-fpm.conf
else
echo $lessphpmem
echo -e "\nCopying php-fpm.conf /usr/local/etc/php-fpm.conf\n"
cp -f $CUR_DIR/config/php-fpm/php-fpm.conf /usr/local/etc/php-fpm.conf
fi # lessphpmem
# only auto reinstall PHP extensions when major PHP upgrade version differs
# from existing installed PHP version
if [[ "$PHPMUVER" != "$PHPCURRENTVER" ]]; then
autodetectinstallextensions
fi
if [[ "$PHPMUVER" != 'NGDEBUG' ]]; then
if [[ ! -f "${CONFIGSCANDIR}/redis.ini" && "$PHPREDIS" = [yY] ]]; then
redisinstall
elif [[ -f "${CONFIGSCANDIR}/redis.ini" && "$PHPREDIS" = [nN] ]]; then
rm -rf ${CONFIGSCANDIR}/redis.ini
fi
fi
else
# only auto reinstall PHP extensions when major PHP upgrade version differs
# from existing installed PHP version
if [[ "$PHPMUVER" != "$PHPCURRENTVER" ]]; then
autodetectinstallextensions
fi
if [[ "$PHPMUVER" != 'NGDEBUG' ]]; then
if [[ ! -f "${CONFIGSCANDIR}/redis.ini" && "$PHPREDIS" = [yY] ]]; then
redisinstall
elif [[ -f "${CONFIGSCANDIR}/redis.ini" && "$PHPREDIS" = [nN] ]]; then
rm -rf ${CONFIGSCANDIR}/redis.ini
fi
fi
fi # overwritephpfpmconf
zendopcacheextfix
if [ ! -f ${CONFIGSCANDIR}/geoip.ini ]; then
# always install geoip module
if [[ "$PHPGEOIP_ALWAYS" = [yY] ]]; then
geoipphpext
fi
fi
cmservice php-fpm restart
if [ -f /usr/local/nginx/html/phpi.php ]; then
# Randomize phpi.php filename
NPHP=$(od -vAn -N4 -tx < /dev/urandom)
NPHP=$(echo ${NPHP} | sed -e 's/\s//')
mv /usr/local/nginx/html/phpi.php /usr/local/nginx/html/${NPHP}_phpi.php
chown nginx:nginx /usr/local/nginx/html/${NPHP}_phpi.php
fi
if [[ "$zendopcacheon" = [yY] && "$OLD_OPCACHEPHP" != [yY] ]]; then
cat ${CENTMINLOGDIR}/zendopcache_passfile.txt
fi
# notes for users if PHP 7.0 detected
php -v | awk -F " " '{print $2}' | head -n1 | cut -d . -f1,2 | grep '7.0'
PHPSEVEN_CHECKVER=$?
echo $PHPSEVEN_CHECKVER
if [[ "$PHPSEVEN_CHECKVER" = '0' ]]; then
cecho "***************************************************" $boldgreen
cecho "PHP 7.0 detected.. remove unsupported PHP extensions manually" $boldyellow
cecho "by removing their ini files:" $boldyellow
cecho "***************************************************" $boldgreen
echo
cecho "rm -rf /etc/centminmod/php.d/igbinary.ini
#rm -rf /etc/centminmod/php.d/imagick.ini
rm -rf /etc/centminmod/php.d/memcache.ini
#rm -rf /etc/centminmod/php.d/mongodb.ini
#rm -rf /etc/centminmod/php.d/redis.ini
rm -rf /etc/centminmod/php.d/suhosin.ini" $boldyellow
echo
cecho "then restart PHP-FPM again..." $boldyellow
echo
fi
echo "***************************************************"
cecho "* PHP upgraded and auto reinstalled PHP extensions" $boldgreen
echo "***************************************************"
fi
# error check
################
if [[ "$ENABLE_MENU" != [yY] ]]; then
ASK "Do would you like to run script cleanup (Highly recommended) ? [y/n] "
if [[ "$key" = [yY] ]];
then
rm -rf $DIR_TMP
echo "Temporary files/folders removed"
fi
ASK "Do you want to delete this script ? [y/n] "
if [[ "$key" = [yY] ]];
then
echo "*************************************************"
cecho "* Deleting Centmin script... " $boldgreen
echo "*************************************************"
echo "Removing..."
rm -f $0
echo "*************************************************"
cecho "* Centmin script deleted" $boldgreen
echo "*************************************************"
fi
fi
}