Просмотр исходного кода

WebUI: Add support for removing/installing php packages

Increase Hestia nginx/php timeouts so install scripts have enough time to finish
Robert Zollner 6 лет назад
Родитель
Сommit
0b94412f3e

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

@@ -32,6 +32,9 @@ if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
     exit
 fi
 
+# Remove backend template
+[ -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
 if [ ! -f "$php_fpm" ] && [ ! -f "$HESTIA/data/templates/$WEB_SYSTEM/PHP-$version.sh" ]; then
     echo "Version is not installed..."
@@ -75,8 +78,6 @@ if [ -f "$php_fpm" ]; then
     echo "apt-get purge $mph"
 fi
 
-# Remove backend template
-rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
 
 #----------------------------------------------------------#
 #                       Hestia                             #

+ 5 - 5
src/deb/nginx/nginx.conf

@@ -17,13 +17,13 @@ http {
     sendfile                        on;
     tcp_nopush                      on;
     tcp_nodelay                     on;
-    client_header_timeout           180s;
-    client_body_timeout             180s;
+    client_header_timeout           600s;
+    client_body_timeout             600s;
     client_header_buffer_size       2k;
     client_body_buffer_size         256k;
     client_max_body_size            256m;
     large_client_header_buffers     4 8k;
-    send_timeout                    60s;
+    send_timeout                    600s;
     keepalive_timeout               30s;
     keepalive_requests              100000;
     reset_timedout_connection       on;
@@ -39,8 +39,8 @@ http {
     fastcgi_busy_buffers_size       256k;
     fastcgi_temp_file_write_size    256k;
     fastcgi_connect_timeout         30s;
-    fastcgi_read_timeout            300s;
-    fastcgi_send_timeout            180s;
+    fastcgi_read_timeout            600s;
+    fastcgi_send_timeout            600s;
 
     # Proxy settings
     proxy_redirect                  off;

+ 1 - 1
src/deb/php/php.ini

@@ -382,7 +382,7 @@ expose_php = Off
 ; Maximum execution time of each script, in seconds
 ; http://php.net/max-execution-time
 ; Note: This directive is hardcoded to 0 for the CLI SAPI
-max_execution_time = 60
+max_execution_time = 600
 
 ; Maximum amount of time each script may spend parsing request data. It's a good
 ; idea to limit this time on productions servers in order to eliminate unexpectedly

+ 68 - 0
web/edit/server/index.php

@@ -33,6 +33,44 @@ if ($v_timezone == 'EST5EDT' ) $v_timezone = 'EDT';
 if ($v_timezone == 'America/Puerto_Rico' ) $v_timezone = 'AST';
 if ($v_timezone == 'America/Halifax' ) $v_timezone = 'ADT';
 
+// List supported php versions
+exec (HESTIA_CMD."v-list-web-templates-backend json", $output, $return_var);
+$backend_templates = json_decode(implode('', $output), true);
+unset($output);
+
+$v_php_versions = [
+    'php-5.6',
+    'php-7.0',
+    'php-7.1',
+    'php-7.2',
+    'php-7.3',
+];
+sort($v_php_versions);
+
+$v_php_versions = array_map(function($php_version) use ($backend_templates, $v_php_versions) {
+    // Mark installed php versions
+
+    if(stripos($php_version,'php') !== 0)
+        return false;
+
+    $phpinfo = (object) [
+        "name" => $php_version,
+        "tpl" => strtoupper(str_replace('.', '_', $php_version)),
+        "version" => str_ireplace('php-', '', $php_version)
+    ];
+
+    if(in_array($phpinfo->tpl, $backend_templates)) {
+        $phpinfo->installed = true;
+    }
+
+    if(array_search($phpinfo->name, array_reverse($v_php_versions, true)) == array_key_last($v_php_versions)) {
+        // Prevent default php version to be removed
+        $phpinfo->protected = true;
+    }
+
+    return $phpinfo;
+}, $v_php_versions);
+
 // List supported languages
 exec (HESTIA_CMD."v-list-sys-languages json", $output, $return_var);
 $languages = json_decode(implode('', $output), true);
@@ -115,6 +153,36 @@ if (!empty($_POST['save'])) {
         $v_hostname = $_POST['v_hostname'];
     }
 
+    // Install/remove php versions
+    if (empty($_SESSION['error_msg'])) {
+        if(!empty($v_php_versions) && count($_POST['v_php_versions'] != count($v_php_versions))) {
+            $post_php = $_POST['v_php_versions'];
+
+            array_map(function($php_version) use ($post_php) {
+
+                if(array_key_exists($php_version->tpl, $post_php)) {
+                    if(!$php_version->installed) {
+                        exec (HESTIA_CMD . "v-add-web-php " . escapeshellarg($php_version->version), $output, $return_var);
+                        check_return_code($return_var, $output);
+                        unset($output);
+                        if(empty($_SESSION['error_msg']))
+                            $php_version->installed = true;
+                    }
+                } else {
+                    if($php_version->installed && !$php_version->protected) {
+                        exec (HESTIA_CMD . "v-delete-web-php " . escapeshellarg($php_version->version), $output, $return_var);
+                        check_return_code($return_var, $output);
+                        unset($output);
+                        if(empty($_SESSION['error_msg']))
+                            $php_version->installed = false;
+                    }
+                }
+
+                return $php_version;
+            }, $v_php_versions);
+        }
+    }
+
     // Change timezone
     if (empty($_SESSION['error_msg'])) {
         if (!empty($_POST['v_timezone'])) {

+ 19 - 0
web/templates/admin/edit_server.html

@@ -243,6 +243,25 @@
                                         </tr>
 
                                         <?php } ?>
+                                        <?php if(count($v_php_versions)): ?>
+                                        <tr>
+                                            <td class="vst-text">
+                                                <?php print __('Enabled multi PHP versions') ?>
+                                            </td>
+                                        </tr>
+                                        <?php foreach($v_php_versions as $php_version): ?>
+                                        <tr>
+                                            <td class="vst-text input-label">
+                                                <input type="checkbox" size="20" class="vst-checkbox"
+                                                    <?=$php_version->installed?'checked':''; ?>
+                                                    <?=$php_version->protected?'disabled':''; ?>
+                                                    id="<?=$php_version->name?>"
+                                                    name="v_php_versions[<?=$php_version->tpl?>]">
+                                                <label for="<?=$php_version->name?>"><?=$php_version->name?></label>
+                                            </td>
+                                        </tr>
+                                        <?php endforeach; ?>
+                                        <?php endif; ?>
                                     </table>
                                 </td>
                             </tr>