diff --git a/core/authorize.php b/core/authorize.php
index fc74bfb..1c62e63 100644
--- a/core/authorize.php
+++ b/core/authorize.php
@@ -21,7 +21,7 @@
  */
 
 // Change the directory to the Drupal root.
-chdir('..');
+chdir(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
 
 /**
  * Global flag to identify update.php and authorize.php runs.
diff --git a/core/install.php b/core/install.php
index 1b921d6..8431928 100644
--- a/core/install.php
+++ b/core/install.php
@@ -6,7 +6,7 @@
  */
 
 // Change the directory to the Drupal root.
-chdir('..');
+chdir(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
 
 /**
  * Global flag to indicate the site is in installation mode.
diff --git a/core/modules/statistics/statistics.php b/core/modules/statistics/statistics.php
index 22d2fb4..c346822 100644
--- a/core/modules/statistics/statistics.php
+++ b/core/modules/statistics/statistics.php
@@ -6,10 +6,11 @@
  */
 
 // Change the directory to the Drupal root.
-chdir('../../..');
+$root = dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))));
+chdir($root);
 
 // Load the Drupal bootstrap.
-include_once dirname(dirname(__DIR__)) . '/includes/bootstrap.inc';
+include_once $root . '/core/includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
 
 if (config('statistics.settings')->get('count_content_views')) {
@@ -27,4 +28,3 @@
       ->execute();
   }
 }
-
diff --git a/core/update.php b/core/update.php
index cee23c4..def5821 100644
--- a/core/update.php
+++ b/core/update.php
@@ -19,7 +19,7 @@
 use Symfony\Component\DependencyInjection\Reference;
 
 // Change the directory to the Drupal root.
-chdir('..');
+chdir(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
 
 // Exit early if an incompatible PHP version would cause fatal errors.
 // The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not
