diff --git a/core/authorize.php b/core/authorize.php
index a72e0ac687..eb54d828cc 100644
--- a/core/authorize.php
+++ b/core/authorize.php
@@ -65,7 +65,9 @@ function authorize_access_allowed(Request $request) {
 try {
   $request = Request::createFromGlobals();
   $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
-  $kernel->prepareLegacyRequest($request);
+  $kernel->boot();
+  $kernel->preHandle($request);
+//  $kernel->prepareLegacyRequest($request);
 }
 catch (HttpExceptionInterface $e) {
   $response = new Response('', $e->getStatusCode());
diff --git a/core/includes/install.inc b/core/includes/install.inc
index 3529d51a98..c6a750a5b3 100644
--- a/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -12,6 +12,8 @@
 use Drupal\Component\Utility\UrlHelper;
 use Drupal\Core\Extension\ExtensionDiscovery;
 use Drupal\Core\Site\Settings;
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
+use Symfony\Component\Routing\Route;
 
 /**
  * Requirement severity -- Informational message only.
@@ -613,6 +615,7 @@ function drupal_install_system($install_state) {
   // Remove the service provider of the early installer.
   unset($GLOBALS['conf']['container_service_providers']['InstallerServiceProvider']);
 
+  // Get the existing request.
   $request = \Drupal::request();
   // Reboot into a full production environment to continue the installation.
   /** @var \Drupal\Core\Installer\InstallerKernel $kernel */
@@ -620,7 +623,14 @@ function drupal_install_system($install_state) {
   $kernel->shutdown();
   // Have installer rebuild from the disk, rather then building from scratch.
   $kernel->rebuildContainer(FALSE);
-  $kernel->prepareLegacyRequest($request);
+  // Reboot the kernel with new container.
+  $kernel->boot();
+  $kernel->preHandle($request);
+  // Setup services which are normally initialized from within stack
+  // middleware or during the request kernel event.
+  if (PHP_SAPI !== 'cli') {
+    $request->setSession($kernel->getContainer()->get('session'));
+  }
 
   // Install base system configuration.
   \Drupal::service('config.installer')->installDefaultConfig('core', 'core');
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 217d4dc781..322ba1da1e 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -717,6 +717,7 @@ public function prepareLegacyRequest(Request $request) {
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
     $this->container->get('request_stack')->push($request);
     $this->container->get('router.request_context')->fromRequest($request);
+    @trigger_error(__METHOD__ . ' is deprecated in Drupal 8.0.x and will be removed before 9.0.0. Only used by legacy front-controller scripts.', E_USER_DEPRECATED);
     return $this;
   }
 
diff --git a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
index f9f97ecaa8..39c614b89e 100644
--- a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
+++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
@@ -16,6 +16,9 @@
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\Yaml\Yaml as SymfonyYaml;
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
+use Symfony\Component\Routing\Route;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
 
 /**
  * Defines a trait for shared functional test setup functionality.
@@ -388,10 +391,15 @@ protected function initUserSession() {
    */
   protected function initKernel(Request $request) {
     $this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE);
-    $this->kernel->prepareLegacyRequest($request);
+    $this->kernel->boot();
+    $this->kernel->preHandle($request);
     // Force the container to be built from scratch instead of loaded from the
     // disk. This forces us to not accidentally load the parent site.
-    return $this->kernel->rebuildContainer();
+    $container = $this->kernel->rebuildContainer();
+    // Add our request to the stack and route context.
+    $container->get('request_stack')->push($request);
+    $container->get('router.request_context')->fromRequest($request);
+    return $container;
   }
 
   /**
@@ -441,7 +449,7 @@ protected function rebuildAll() {
     // @todo Test-specific setUp() methods may set up further fixtures; find a
     //   way to execute this after setUp() is done, or to eliminate it entirely.
     $this->resetAll();
-    $this->kernel->prepareLegacyRequest(\Drupal::request());
+//    $this->kernel->prepareLegacyRequest(\Drupal::request());
 
     // Explicitly call register() again on the container registered in \Drupal.
     // @todo This should already be called through
@@ -575,7 +583,9 @@ protected function prepareEnvironment() {
     $kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader);
     // TestRunnerKernel expects the working directory to be DRUPAL_ROOT.
     chdir(DRUPAL_ROOT);
-    $kernel->prepareLegacyRequest($request);
+    $kernel->boot();
+    $kernel->preHandle($request);
+//    $kernel->prepareLegacyRequest($request);
     $this->prepareDatabasePrefix();
 
     $this->originalSite = $kernel->findSitePath($request);
diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php
index 3e54b3f085..de8996270e 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBase.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -28,6 +28,8 @@
 use Symfony\Component\HttpFoundation\Request;
 use org\bovigo\vfs\vfsStream;
 use org\bovigo\vfs\visitor\vfsStreamPrintVisitor;
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
+use Symfony\Component\Routing\Route;
 
 /**
  * Base class for functional integration tests.
@@ -318,6 +320,18 @@ public function getDatabasePrefix() {
     return $this->databasePrefix;
   }
 
+  private function prepareLegacyRequest(Request $request, ContainerBuilder $container) {
+    // Setup services which are normally initialized from within stack
+    // middleware or during the request kernel event.
+    if (PHP_SAPI !== 'cli') {
+      $request->setSession($this->container->get('session'));
+    }
+    $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
+    $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
+    $container->get('request_stack')->push($request);
+    $container->get('router.request_context')->fromRequest($request);
+  }
+
   /**
    * Bootstraps a kernel for a test.
    */
@@ -363,7 +377,10 @@ private function bootKernel() {
     // DrupalKernel::boot() is not sufficient as it does not invoke preHandle(),
     // which is required to initialize legacy global variables.
     $request = Request::create('/');
-    $kernel->prepareLegacyRequest($request);
+    $kernel->boot();
+    $kernel->preHandle($request);
+    $this->prepareLegacyRequest($request, $kernel->getContainer());
+//    $kernel->prepareLegacyRequest($request);
 
     // register() is only called if a new container was built/compiled.
     $this->container = $kernel->getContainer();
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
index e7c79f380a..5b8fb0f7dc 100644
--- a/core/tests/Drupal/Tests/BrowserTestBase.php
+++ b/core/tests/Drupal/Tests/BrowserTestBase.php
@@ -27,6 +27,8 @@
 use Psr\Http\Message\RequestInterface;
 use Psr\Http\Message\ResponseInterface;
 use Symfony\Component\CssSelector\CssSelectorConverter;
+use Symfony\Component\Routing\Route;
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 
 /**
  * Provides a test case for functional Drupal tests.
@@ -975,7 +977,10 @@ public function installDrupal() {
     $this->prepareSettings();
     $this->doInstall();
     $this->initSettings();
-    $container = $this->initKernel(\Drupal::request());
+    $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
+    $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
+    $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
+    $container = $this->initKernel($request);
     $this->initConfig($container);
     $this->installModulesFromClassProperty($container);
     $this->rebuildAll();
