Skip to content

Commit 7b6e4b7

Browse files
authored
Allow set "System" php version via Web GUI (hestiacp#2357)
* Fix broken check Old check did not work properly due to missing files * Allow editing System PHP version
1 parent 972ae17 commit 7b6e4b7

File tree

4 files changed

+96
-4
lines changed

4 files changed

+96
-4
lines changed

bin/v-change-sys-php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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"

bin/v-delete-web-php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ fi
4242
[ -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl ] && rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
4343

4444
# Check if php version exists
45-
if [ ! -f "$php_fpm" ] && [ ! -f "$HESTIA/data/templates/$WEB_SYSTEM/PHP-$version.sh" ]; then
45+
version_check=$($HESTIA/bin/v-list-sys-php plain | grep "$version");
46+
if [ -z "$version_check" ] ; then
4647
echo "ERROR: Specified PHP version is not installed."
47-
exit
48+
exit "$E_INVALID";
4849
fi
4950

5051
# Perform verification if read-only mode is enabled

web/edit/server/index.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,15 @@
276276
}, $v_php_versions);
277277
}
278278
}
279-
279+
280+
if (empty($_SESSION['error_msg'])) {
281+
if($_POST['v_php_default_version'] != DEFAULT_PHP_VERSION) {
282+
exec(HESTIA_CMD . "v-change-sys-php " . escapeshellarg($_POST['v_php_default_version']), $output, $return_var);
283+
check_return_code($return_var, $output);
284+
unset($output);
285+
}
286+
}
287+
280288
// Change timezone
281289
if (empty($_SESSION['error_msg'])) {
282290
if (!empty($_POST['v_timezone'])) {

web/templates/pages/edit_server.html

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,39 @@
303303
<?php endforeach; ?>
304304
<?php endforeach; ?>
305305
<?php endif; ?>
306+
<?php if(!empty($_SESSION['WEB_BACKEND'])){
307+
?>
308+
<tr>
309+
<td class="vst-text step-top">
310+
<?=_('System PHP version');?></span>
311+
</td>
312+
</tr>
313+
<tr>
314+
<td>
315+
<select class="vst-list" name="v_php_default_version">
316+
<?php foreach($v_php_versions as $php_version){
317+
if($php_version -> installed){
318+
?>
319+
<option value="<?=$php_version->version; ?>" <?php if($php_version->name == DEFAULT_PHP_VERSION){ echo "selected" ;}?> ><?=$php_version->name; ?></option>
320+
<?php
321+
}
322+
}
323+
?>
324+
</select>
325+
</td>
326+
</tr>
327+
<?php
328+
}
329+
?>
306330
<tr>
307331
<td>
308332
<br />
309333
</td>
310334
</tr>
335+
311336
</table>
312337
</td>
313338
</tr>
314-
315339
<!-- DNS Server tab -->
316340
<?php if (!empty($_SESSION['DNS_SYSTEM'])) { ?>
317341
<tr>

0 commit comments

Comments
 (0)