Parcourir la source

Allow set "System" php version via Web GUI (#2357)

* Fix broken check

Old check did not work properly due to missing files

* Allow editing System PHP version
Jaap Marcus il y a 4 ans
Parent
commit
7b6e4b7541
4 fichiers modifiés avec 96 ajouts et 4 suppressions
  1. 59 0
      bin/v-change-sys-php
  2. 3 2
      bin/v-delete-web-php
  3. 9 1
      web/edit/server/index.php
  4. 25 1
      web/templates/pages/edit_server.html

+ 59 - 0
bin/v-change-sys-php

@@ -0,0 +1,59 @@
+#!/bin/bash
+# info: Change default php version server wide
+# options: VERSION
+
+# example: v-change-sys-php 8.0
+
+version=$1
+
+# Includes
+# shellcheck source=/etc/hestiacp/hestia.conf
+source /etc/hestiacp/hestia.conf
+# shellcheck source=/usr/local/hestia/func/main.sh
+source $HESTIA/func/main.sh
+# load config file
+source_conf "$HESTIA/conf/hestia.conf"
+
+#----------------------------------------------------------#
+#                Variables & Functions                     #
+#----------------------------------------------------------#
+
+check_args '1' "$#" 'VERSION'
+
+# Verify php version format
+if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
+    echo "The specified PHP version format is invalid, it should look like [0-9].[0-9]."
+    echo "Example: 7.0, 7.4, 8.0"
+    exit "$E_INVALID";
+fi
+
+# Check if php version exists
+version_check=$($HESTIA/bin/v-list-sys-php plain | grep "$version");
+if [ -z "$version_check" ] ; then
+    echo "ERROR: Specified PHP version is not installed."
+    exit "$E_INVALID";
+fi
+
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Set file locations
+php_fpm="/etc/init.d/php$version-fpm"
+
+
+rm -f /etc/php/*/fpm/pool.d/www.conf
+cp -f $HESTIA/install/deb/php-fpm/www.conf /etc/php/$version/fpm/pool.d/www.conf
+$HESTIA/bin/v-restart-web-backend
+
+update-alternatives --set php /usr/bin/php$version
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+log_event "$OK" "$ARGUMENTS"

+ 3 - 2
bin/v-delete-web-php

@@ -42,9 +42,10 @@ fi
 [ -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl ] && rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
 [ -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl ] && rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
 
 
 # Check if php version exists
 # Check if php version exists
-if [ ! -f "$php_fpm" ] && [ ! -f "$HESTIA/data/templates/$WEB_SYSTEM/PHP-$version.sh" ]; then
+version_check=$($HESTIA/bin/v-list-sys-php plain | grep "$version");
+if [ -z "$version_check" ] ; then
     echo "ERROR: Specified PHP version is not installed."
     echo "ERROR: Specified PHP version is not installed."
-    exit
+    exit "$E_INVALID";
 fi
 fi
 
 
 # Perform verification if read-only mode is enabled
 # Perform verification if read-only mode is enabled

+ 9 - 1
web/edit/server/index.php

@@ -276,7 +276,15 @@ if (!empty($_POST['save'])) {
             }, $v_php_versions);
             }, $v_php_versions);
         }
         }
     }
     }
-
+    
+    if (empty($_SESSION['error_msg'])) {
+        if($_POST['v_php_default_version'] != DEFAULT_PHP_VERSION) {
+            exec(HESTIA_CMD . "v-change-sys-php " . escapeshellarg($_POST['v_php_default_version']), $output, $return_var);
+            check_return_code($return_var, $output);
+            unset($output);
+        }   
+    }
+    
     // Change timezone
     // Change timezone
     if (empty($_SESSION['error_msg'])) {
     if (empty($_SESSION['error_msg'])) {
         if (!empty($_POST['v_timezone'])) {
         if (!empty($_POST['v_timezone'])) {

+ 25 - 1
web/templates/pages/edit_server.html

@@ -303,15 +303,39 @@
 											<?php endforeach; ?>
 											<?php endforeach; ?>
 										<?php endforeach; ?>
 										<?php endforeach; ?>
 									<?php endif; ?>
 									<?php endif; ?>
+									<?php if(!empty($_SESSION['WEB_BACKEND'])){
+									?>
+									<tr>
+										<td class="vst-text step-top">
+											<?=_('System PHP version');?></span>
+										</td>
+									</tr>
+									<tr>
+										<td>
+											<select class="vst-list" name="v_php_default_version">
+												<?php foreach($v_php_versions as $php_version){
+												if($php_version -> installed){
+												?>
+												<option value="<?=$php_version->version; ?>" <?php if($php_version->name == DEFAULT_PHP_VERSION){ echo "selected" ;}?> ><?=$php_version->name; ?></option>
+												<?php	
+												}
+												}
+												?>
+											</select>
+										</td>
+									</tr>
+									<?php
+									}
+									?>
 									<tr>
 									<tr>
 										<td>
 										<td>
 											<br />
 											<br />
 										</td>
 										</td>
 									</tr>
 									</tr>
+
 								</table>
 								</table>
 							</td>
 							</td>
 						</tr>
 						</tr>
-
 						<!-- DNS Server tab -->
 						<!-- DNS Server tab -->
 						<?php if (!empty($_SESSION['DNS_SYSTEM'])) { ?>
 						<?php if (!empty($_SESSION['DNS_SYSTEM'])) { ?>
 							<tr>
 							<tr>