diff --git a/core/authorize.php b/core/authorize.php
index 114dcd3ad1de632ab577955c7a52160e485a70b7..c53361848396413695d2b2d8a367c1525b4dda51 100644
--- a/core/authorize.php
+++ b/core/authorize.php
@@ -23,11 +23,6 @@
 // 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,11 +58,11 @@ function authorize_access_allowed() {
 
 // *** Real work of the script begins here. ***
 
-require_once DRUPAL_ROOT . '/core/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';
-require_once DRUPAL_ROOT . '/core/includes/ajax.inc';
+require_once __DIR__ . '/includes/bootstrap.inc';
+require_once __DIR__ . '/includes/common.inc';
+require_once __DIR__ . '/includes/file.inc';
+require_once __DIR__ . '/includes/module.inc';
+require_once __DIR__ . '/includes/ajax.inc';
 
 // We prepare only a minimal bootstrap. This includes the database and
 // variables, however, so we have access to the class autoloader.
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index faee574866074230885ab47dec65c5b3d3c4687f..e1c15fea0e7bdf9942e8fcb0d4587daa87496869 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -326,6 +326,13 @@
  */
 const CONFIG_STAGING_DIRECTORY = 'staging';
 
+/**
+ * Defines the root directory of the Drupal installation.
+ *
+ * This strips two levels of directories off the current directory.
+ */
+define('DRUPAL_ROOT', dirname(dirname(__DIR__)));
+
 /**
  * Starts the timer with the specified name.
  *
diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index d2e461ed99c6f3650915f04809456feacd70940e..5bde07794bb6e230139045171b8efa0a6189e678 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -257,7 +257,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 6f046b21e3da36214111215ab33b0c11b3b80401..23770a9cdeb8d4f12ac22ded407c0327eb2d796e 100644
--- a/core/install.php
+++ b/core/install.php
@@ -8,11 +8,6 @@
 // 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 +27,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 87e3daebeccb4c776c39e49ef62467ca364332f2..22d2fb457a2849e7dfd9028808e7da185e537141 100644
--- a/core/modules/statistics/statistics.php
+++ b/core/modules/statistics/statistics.php
@@ -8,12 +8,8 @@
 // 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 84476e3a3ee11313c5fe366d3b6f5a3e71223fd5..5e5e7028e0f6f8f342ee0bcb0d0aaa3abfd9dfb4 100644
--- a/core/modules/system/tests/http.php
+++ b/core/modules/system/tests/http.php
@@ -18,7 +18,5 @@
 
 // Change current directory to the Drupal root.
 chdir('../../../..');
-
-define('DRUPAL_ROOT', getcwd());
-require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc';
 drupal_handle_request(TRUE);
diff --git a/core/modules/system/tests/https.php b/core/modules/system/tests/https.php
index 0d96896389f67342925808c6fc35c362b5c3b415..cc2bd45240cd57b3fa71a1a10f96053ec0350b0d 100644
--- a/core/modules/system/tests/https.php
+++ b/core/modules/system/tests/https.php
@@ -17,7 +17,5 @@
 
 // Change current directory to the Drupal root.
 chdir('../../../..');
-
-define('DRUPAL_ROOT', getcwd());
-require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc';
 drupal_handle_request(TRUE);
diff --git a/core/scripts/password-hash.sh b/core/scripts/password-hash.sh
index b91cd41281ddf576b356ab5d2489ab53f7342524..485f497ac64d41e2d58e6a299798368d88e3147f 100755
--- a/core/scripts/password-hash.sh
+++ b/core/scripts/password-hash.sh
@@ -79,9 +79,9 @@
 }
 
 chdir('..');
-define('DRUPAL_ROOT', getcwd());
-
-include_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+$core = dirname(__DIR__);
+include_once $core . '/includes/password.inc';
+include_once $core . '/includes/bootstrap.inc';
 
 $password_hasher = drupal_container()->get('password');
 
diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index 5b666c1a7d0076ae511694ef961feda30114375e..a736492e2aa088cbe18c883b690b1c1b6cb2acdc 100755
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
@@ -311,8 +311,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 d24d6e0f82440e6a17ef261ee2c21f2495b0d724..99975d0f9647cb9bfcf3bc26e344e94ad9c0efde 100644
--- a/core/update.php
+++ b/core/update.php
@@ -21,11 +21,6 @@
 // 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
@@ -404,12 +399,12 @@ 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 DRUPAL_ROOT . '/core/includes/update.inc';
-require_once DRUPAL_ROOT . '/core/includes/common.inc';
-require_once DRUPAL_ROOT . '/core/includes/file.inc';
-require_once DRUPAL_ROOT . '/core/includes/unicode.inc';
-require_once DRUPAL_ROOT . '/core/includes/schema.inc';
+require_once __DIR__ . '/includes/bootstrap.inc';
+require_once __DIR__ . '/includes/update.inc';
+require_once __DIR__ . '/includes/common.inc';
+require_once __DIR__ . '/includes/file.inc';
+require_once __DIR__ . '/includes/unicode.inc';
+require_once __DIR__ . '/includes/schema.inc';
 update_prepare_d8_bootstrap();
 
 // Determine if the current user has access to run update.php.
diff --git a/index.php b/index.php
index df30e3f9f7edc214b83c9cc7797c434e6577f145..f0949e0638b8d7662122d9c3e43e2a994864e1b0 100644
--- a/index.php
+++ b/index.php
@@ -8,10 +8,5 @@
  * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
  */
 
-/**
- * Root directory of Drupal installation.
- */
-define('DRUPAL_ROOT', getcwd());
-
-require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
+require_once __DIR__ . '/core/includes/bootstrap.inc';
 drupal_handle_request();