diff --git a/core/authorize.php b/core/authorize.php
index a439975..a66e925 100644
--- a/core/authorize.php
+++ b/core/authorize.php
@@ -20,14 +20,6 @@
  * @link authorize Authorized operation helper functions @endlink
  */
 
-// Change the directory to the Drupal root.
-chdir('..');
-
-/**
- * Defines the root directory of the Drupal installation.
- */
-define('DRUPAL_ROOT', getcwd());
-
 /**
  * Global flag to identify update.php and authorize.php runs.
  *
@@ -63,7 +55,7 @@ function authorize_access_allowed() {
 
 // *** Real work of the script begins here. ***
 
-require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+require_once __DIR__ . '/includes/bootstrap.inc';
 require_once DRUPAL_ROOT . '/core/includes/common.inc';
 require_once DRUPAL_ROOT . '/core/includes/file.inc';
 require_once DRUPAL_ROOT . '/core/includes/module.inc';
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 3453b2a..3b1f229 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -335,6 +335,11 @@
 const CONFIG_STAGING_DIRECTORY = 'staging';
 
 /**
+ * Defines the root directory of the Drupal installation.
+ */
+define('DRUPAL_ROOT', dirname(dirname(__DIR__)));
+
+/**
  * Starts the timer with the specified name.
  *
  * If you start and stop the same timer multiple times, the measured intervals
@@ -627,6 +632,9 @@ function drupal_environment_initialize() {
     $_SERVER['HTTP_HOST'] = '';
   }
 
+  // Ensure we are operating in the Drupal root.
+  chdir(DRUPAL_ROOT);
+
   // @todo Refactor with the Symfony Request object.
   _current_path(request_path());
 
diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index b1d3b50..0177615 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -247,7 +247,7 @@ function install_begin_request(&$install_state) {
   }
 
   // Allow command line scripts to override server variables used by Drupal.
-  require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+  require_once __DIR__ . '/bootstrap.inc';
 
   if (!$install_state['interactive']) {
     drupal_override_server_variables($install_state['server']);
diff --git a/core/install.php b/core/install.php
index 6f046b2..cf40813 100644
--- a/core/install.php
+++ b/core/install.php
@@ -5,14 +5,6 @@
  * Initiates a browser-based installation of Drupal.
  */
 
-// Change the directory to the Drupal root.
-chdir('..');
-
-/**
- * Defines the root directory of the Drupal installation.
- */
-define('DRUPAL_ROOT', getcwd());
-
 /**
  * Global flag to indicate the site is in installation mode.
  *
@@ -32,5 +24,5 @@
 }
 
 // Start the installer.
-require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
+require_once __DIR__ . '/includes/install.core.inc';
 install_drupal();
diff --git a/core/modules/statistics/statistics.php b/core/modules/statistics/statistics.php
index 87e3dae..123d76d 100644
--- a/core/modules/statistics/statistics.php
+++ b/core/modules/statistics/statistics.php
@@ -5,15 +5,8 @@
  * Handles counts of node views via AJAX with minimal bootstrap.
  */
 
-// Change the directory to the Drupal root.
-chdir('../../..');
-
-/**
-* Root directory of Drupal installation.
-*/
-define('DRUPAL_ROOT', getcwd());
-
-include_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+// Load the Drupal bootstrap.
+include_once dirname(dirname(__DIR__)) . '/includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
 
 if (config('statistics.settings')->get('count_content_views')) {
diff --git a/core/modules/system/tests/http.php b/core/modules/system/tests/http.php
index 297e3c7..5f67ca9 100644
--- a/core/modules/system/tests/http.php
+++ b/core/modules/system/tests/http.php
@@ -19,10 +19,8 @@
   $_SERVER[$key] = str_replace('https://', 'http://', $_SERVER[$key]);
 }
 
-// Change current directory to the Drupal root.
-chdir('../../../..');
-define('DRUPAL_ROOT', getcwd());
-require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+// Load the Drupal bootstrap.
+require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc';
 
 // Make sure this file can only be used by simpletest.
 drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
diff --git a/core/modules/system/tests/https.php b/core/modules/system/tests/https.php
index 8e09a5d..5cbe62a 100644
--- a/core/modules/system/tests/https.php
+++ b/core/modules/system/tests/https.php
@@ -18,10 +18,8 @@
   $_SERVER[$key] = str_replace('http://', 'https://', $_SERVER[$key]);
 }
 
-// Change current directory to the Drupal root.
-chdir('../../../..');
-define('DRUPAL_ROOT', getcwd());
-require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+// Load the Drupal bootstrap.
+require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc';
 
 // Make sure this file can only be used by simpletest.
 drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
diff --git a/core/scripts/password-hash.sh b/core/scripts/password-hash.sh
index 8109af4..c6dd84e 100755
--- a/core/scripts/password-hash.sh
+++ b/core/scripts/password-hash.sh
@@ -78,8 +78,9 @@
   }
 }
 
-chdir('..');
-define('DRUPAL_ROOT', getcwd());
+$core = dirname(__DIR__);
+include_once $core . '/includes/password.inc';
+include_once $core . '/includes/bootstrap.inc';
 
 include_once DRUPAL_ROOT . '/core/includes/password.inc';
 include_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index 2395a84..a9175ff 100755
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
@@ -297,9 +297,7 @@ function simpletest_script_init($server_software) {
     }
   }
 
-  chdir(realpath(__DIR__ . '/../..'));
-  define('DRUPAL_ROOT', getcwd());
-  require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+  require_once dirname(__DIR__) . '/includes/bootstrap.inc';
 }
 
 /**
diff --git a/core/update.php b/core/update.php
index 2273b40..26c896d 100644
--- a/core/update.php
+++ b/core/update.php
@@ -18,14 +18,6 @@
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\DependencyInjection\Reference;
 
-// Change the directory to the Drupal root.
-chdir('..');
-
-/**
- * Defines the root directory of the Drupal installation.
- */
-define('DRUPAL_ROOT', getcwd());
-
 // Exit early if an incompatible PHP version would cause fatal errors.
 // The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not
 // yet available. It is defined in bootstrap.inc, but it is not possible to
@@ -384,7 +376,7 @@ function update_check_requirements($skip_warnings = FALSE) {
 
 // We prepare a minimal bootstrap for the update requirements check to avoid
 // reaching the PHP memory limit.
-require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+require_once __DIR__ . '/includes/bootstrap.inc';
 require_once DRUPAL_ROOT . '/core/includes/update.inc';
 require_once DRUPAL_ROOT . '/core/includes/common.inc';
 require_once DRUPAL_ROOT . '/core/includes/file.inc';
diff --git a/index.php b/index.php
index 38177ab..d3af086 100644
--- a/index.php
+++ b/index.php
@@ -14,17 +14,12 @@
 use Drupal\Core\DrupalKernel;
 use Symfony\Component\HttpFoundation\Request;
 
-/**
- * Root directory of Drupal installation.
- */
-define('DRUPAL_ROOT', getcwd());
-
 // Bootstrap all of Drupal's subsystems, but do not initialize anything that
 // depends on the fully resolved Drupal path, because path resolution happens
 // during the REQUEST event of the kernel.
 // @see Drupal\Core\EventSubscriber\PathSubscriber;
 // @see Drupal\Core\EventSubscriber\LegacyRequestSubscriber;
-require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+require_once __DIR__ . '/core/includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
 
 // @todo Figure out how best to handle the Kernel constructor parameters.
