1+ #! /bin/bash
2+ # info: Change default php version server wide
3+ # options: VERSION
4+
5+ # example: v-change-sys-php 8.0
6+
7+ version=$1
8+
9+ # Includes
10+ # shellcheck source=/etc/hestiacp/hestia.conf
11+ source /etc/hestiacp/hestia.conf
12+ # shellcheck source=/usr/local/hestia/func/main.sh
13+ source $HESTIA /func/main.sh
14+ # load config file
15+ source_conf " $HESTIA /conf/hestia.conf"
16+
17+ # ----------------------------------------------------------#
18+ # Variables & Functions #
19+ # ----------------------------------------------------------#
20+
21+ check_args ' 1' " $# " ' VERSION'
22+
23+ # Verify php version format
24+ if [[ ! $version =~ ^[0-9]\. [0-9]+ ]]; then
25+ echo " The specified PHP version format is invalid, it should look like [0-9].[0-9]."
26+ echo " Example: 7.0, 7.4, 8.0"
27+ exit " $E_INVALID " ;
28+ fi
29+
30+ # Check if php version exists
31+ version_check=$( $HESTIA /bin/v-list-sys-php plain | grep " $version " ) ;
32+ if [ -z " $version_check " ] ; then
33+ echo " ERROR: Specified PHP version is not installed."
34+ exit " $E_INVALID " ;
35+ fi
36+
37+
38+ # Perform verification if read-only mode is enabled
39+ check_hestia_demo_mode
40+
41+ # ----------------------------------------------------------#
42+ # Action #
43+ # ----------------------------------------------------------#
44+
45+ # Set file locations
46+ php_fpm=" /etc/init.d/php$version -fpm"
47+
48+
49+ rm -f /etc/php/* /fpm/pool.d/www.conf
50+ cp -f $HESTIA /install/deb/php-fpm/www.conf /etc/php/$version /fpm/pool.d/www.conf
51+ $HESTIA /bin/v-restart-web-backend
52+
53+ update-alternatives --set php /usr/bin/php$version
54+
55+ # ----------------------------------------------------------#
56+ # Hestia #
57+ # ----------------------------------------------------------#
58+
59+ log_event " $OK " " $ARGUMENTS "
0 commit comments