diff --git includes/common.inc includes/common.inc
index 5a7e340..65d4bc2 100644
--- includes/common.inc
+++ includes/common.inc
@@ -197,20 +197,24 @@ function drupal_get_region_content($region = NULL, $delimiter = ' ') {
 /**
  * Get the name of the currently active install profile.
  *
- * When this function is called during Drupal's initial installation process,
- * the name of the profile that's about to be installed is stored in the global
- * installation state. At all other times, the standard Drupal systems variable
- * table contains the name of the current profile, and we can call variable_get()
- * to determine what one is active.
+ * This value is stored in the settings.php file generated during installation.
+ *
+ * Because we need to have this information before the database connection is 
+ * initialized, to correctly determine where to search for modules and themes,
+ * we can not use the variable system to store this value.
+ *
+ * If this function is called during the initial installation process,
+ * the global variable will be initialized to the profile requested by the user
+ * and then stored in the settings file for future use.
  *
  * @return $profile
  *   The name of the install profile.
  */
 function drupal_get_profile() {
-  global $install_state;
+  global $install_profile;
 
-  if (isset($install_state['parameters']['profile'])) {
-    $profile = $install_state['parameters']['profile'];
+  if (!empty($install_profile)) {
+    $profile = $install_profile;
   }
   else {
     $profile = variable_get('install_profile', 'standard');
diff --git includes/install.core.inc includes/install.core.inc
index 3b39e08..932c542 100644
--- includes/install.core.inc
+++ includes/install.core.inc
@@ -1014,6 +1014,11 @@ function install_settings_form_submit($form, &$form_state) {
     'value'    => drupal_hash_base64(drupal_random_bytes(55)),
     'required' => TRUE,
   );
+  $settings['install_profile'] = array(
+    'value' => $install_state['parameters']['profile'],
+    'required' => TRUE
+  );
+ 
   drupal_rewrite_settings($settings);
   // Indicate that the settings file has been verified, and check the database
   // for the last completed task, now that we have a valid connection. This
@@ -1530,9 +1535,6 @@ function install_finished(&$install_state) {
   // Register actions declared by any modules.
   actions_synchronize();
 
-  // Remember the profile which was used.
-  variable_set('install_profile', drupal_get_profile());
-
   // Install profiles are always loaded last
   db_update('system')
     ->fields(array('weight' => 1000))
diff --git includes/update.inc includes/update.inc
index da91db9..1786f6c 100644
--- includes/update.inc
+++ includes/update.inc
@@ -354,12 +354,31 @@ function update_fix_d7_requirements() {
 
   // Rewrite the settings.php file if necessary, see
   // update_prepare_d7_bootstrap().
-  global $update_rewrite_settings, $db_url, $db_prefix;
+  global $update_rewrite_settings, $db_url, $db_prefix, $install_profile;
   if (!empty($update_rewrite_settings)) {
     $databases = update_parse_db_url($db_url, $db_prefix);
     $salt = drupal_hash_base64(drupal_random_bytes(55));
     file_put_contents(conf_path() . '/settings.php', "\n" . '$databases = ' . var_export($databases, TRUE) . ";\n\$drupal_hash_salt = '$salt';", FILE_APPEND);
+
+    // The install profile was renamed from 'default' to 'standard'.
+    // This change was originally handled in system_update_7049(), 
+    // but because we no longer use a variable to store the profile name,
+    // it is no longer necessary.
+    $profile = variable_get('install_profile', 'standard');
+    if ($profile == 'default') {
+      $profile = 'standard';
+    }
+
+    file_put_contents(conf_path() . '/settings.php', "\n" . '$install_profile = ' . var_export($profile, TRUE) . ';', FILE_APPEND);
+
+    // We modify the $install_profile global, so that future calls to drupal_get_profile() will return the correct value,
+    //  because the settings.php file has already been loaded at this point.
+    $install_profile = $profile;
+
+    // Remove the unnecessary variable.
+    variable_del('install_profile');
   }
+
   if (drupal_get_installed_schema_version('system') < 7000 && !variable_get('update_d7_requirements', FALSE)) {
     // Change 6.x system table field values to 7.x equivalent.
     // Change field values.
diff --git modules/simpletest/drupal_web_test_case.php modules/simpletest/drupal_web_test_case.php
index 257921a..46e836c 100644
--- modules/simpletest/drupal_web_test_case.php
+++ modules/simpletest/drupal_web_test_case.php
@@ -591,7 +591,7 @@ class DrupalUnitTestCase extends DrupalTestCase {
    * method.
    */
   protected function setUp() {
-    global $conf;
+    global $conf, $install_profile;
 
     // Store necessary current values before switching to the test environment.
     $this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
@@ -1166,7 +1166,7 @@ class DrupalWebTestCase extends DrupalTestCase {
    *   either a single array or a variable number of string arguments.
    */
   protected function setUp() {
-    global $user, $language, $conf;
+    global $user, $language, $conf, $install_profile;
 
     // Generate a temporary prefixed database to ensure that tests have a clean starting point.
     $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
@@ -1236,8 +1236,8 @@ class DrupalWebTestCase extends DrupalTestCase {
     variable_set('file_private_path', $private_files_directory);
     variable_set('file_temporary_path', $temp_files_directory);
 
-    // Include the testing profile.
-    variable_set('install_profile', $this->profile);
+    // Include the default profile.
+    $install_profile = $this->profile;
     $profile_details = install_profile_info($this->profile, 'en');
 
     // Install the modules specified by the testing profile.
diff --git modules/system/system.install modules/system/system.install
index 56019a8..fb3a10a 100644
--- modules/system/system.install
+++ modules/system/system.install
@@ -2352,9 +2352,10 @@ function system_update_7048() {
  * Rename 'Default' profile to 'Standard.'
  */
 function system_update_7049() {
-  if (variable_get('install_profile', 'standard') == 'default') {
-    variable_set('install_profile', 'standard');
-  }
+  // This change is now handled by update_fix_d7_requirements().
+  // We no longer store the install profile in a variable, but rather
+  // keep it in the settings.php, as it may need to be accessed
+  // before the database connection has been made.
 }
 
 /**
diff --git sites/default/default.settings.php sites/default/default.settings.php
index d1bb23a..b68d0d3 100644
--- sites/default/default.settings.php
+++ sites/default/default.settings.php
@@ -213,6 +213,15 @@ $update_free_access = FALSE;
 $drupal_hash_salt = '';
 
 /**
+ * Install profile:
+ *
+ * Drupal can be installed with one of several install profiles, which
+ * will provide some initial configuration and an additional location for
+ * modules and themes to be loaded from.
+ */
+ $install_profile = 'standard';
+
+/**
  * Base URL (optional).
  *
  * If Drupal is generating incorrect URLs on your site, which could
