Standalone.civi-setup.php - Fix 'HTTP'/'HTTPS' detection on non-Apache environments
authorTim Otten <totten@civicrm.org>
Sun, 16 Jul 2023 03:32:14 +0000 (20:32 -0700)
committerTim Otten <totten@civicrm.org>
Sun, 16 Jul 2023 05:12:04 +0000 (22:12 -0700)
setup/plugins/init/Standalone.civi-setup.php

index ca71d74ea9d794cf86c54fa322fd7a3cf47f0bf1..7c0820b4c83e96477f18a5a53e90ed46ecf89693 100644 (file)
@@ -9,6 +9,17 @@ if (!defined('CIVI_SETUP')) {
   exit("Installation plugins must only be loaded by the installer.\n");
 }
 
+function _standalone_setup_scheme(): string {
+  if ((!empty($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] == 'https') ||
+    (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ||
+    (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443')) {
+    return 'https';
+  }
+  else {
+    return 'http';
+  }
+}
+
 \Civi\Setup::dispatcher()
   ->addListener('civi.setup.checkAuthorized', function (\Civi\Setup\Event\CheckAuthorizedEvent $e) {
     $model = $e->getModel();
@@ -82,7 +93,7 @@ if (!defined('CIVI_SETUP')) {
     // original: $model->cmsBaseUrl = $_SERVER['HTTP_ORIGIN'] ?: $_SERVER['HTTP_REFERER'];
     if (empty($model->cmsBaseUrl)) {
       // A buildkit install (which uses cv core:install) sets this correctly. But a standard composer-then-website type install does not.
-      $model->cmsBaseUrl = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
+      $model->cmsBaseUrl = _standalone_setup_scheme() . '://' . $_SERVER['HTTP_HOST'];
     }
 
     // These paths get set as