function install_check_requirements
Same name in other branches
- 7.x includes/install.core.inc \install_check_requirements()
- 8.9.x core/includes/install.core.inc \install_check_requirements()
- 10 core/includes/install.core.inc \install_check_requirements()
- 11.x core/includes/install.core.inc \install_check_requirements()
Checks installation requirements and reports any errors.
1 call to install_check_requirements()
- install_verify_requirements in core/
includes/ install.core.inc - Verifies the requirements for installing Drupal.
File
-
core/
includes/ install.core.inc, line 2065
Code
function install_check_requirements($install_state) {
$profile = $install_state['parameters']['profile'];
// Check the profile requirements.
$requirements = drupal_check_profile($profile);
if ($install_state['settings_verified']) {
return $requirements;
}
// If Drupal is not set up already, we need to try to create the default
// settings and services files.
$default_files = [];
$default_files['settings.php'] = [
'file' => 'settings.php',
'file_default' => 'default.settings.php',
'title_default' => t('Default settings file'),
'description_default' => t('The default settings file does not exist.'),
'title' => t('Settings file'),
];
$file_system = \Drupal::service('file_system');
foreach ($default_files as $default_file_info) {
$readable = FALSE;
$writable = FALSE;
$site_path = './' . \Drupal::getContainer()->getParameter('site.path');
$file = $site_path . "/{$default_file_info['file']}";
$default_file = "./sites/default/{$default_file_info['file_default']}";
$exists = FALSE;
// Verify that the directory exists.
if (drupal_verify_install_file($site_path, FILE_EXIST, 'dir')) {
if (drupal_verify_install_file($file, FILE_EXIST)) {
// If it does, make sure it is writable.
$readable = drupal_verify_install_file($file, FILE_READABLE);
$writable = drupal_verify_install_file($file, FILE_WRITABLE);
$exists = TRUE;
}
}
// If the default $default_file does not exist, or is not readable,
// report an error.
if (!drupal_verify_install_file($default_file, FILE_EXIST | FILE_READABLE)) {
$requirements["default {$file} file exists"] = [
'title' => $default_file_info['title_default'],
'value' => $default_file_info['description_default'],
'severity' => REQUIREMENT_ERROR,
'description' => t('The @drupal installer requires that the %default-file file must not be deleted or modified from the original download.', [
'@drupal' => drupal_install_profile_distribution_name(),
'%default-file' => $default_file,
]),
];
}
elseif (!$exists) {
$copied = drupal_verify_install_file($site_path, FILE_EXIST | FILE_WRITABLE, 'dir') && @copy($default_file, $file);
if ($copied) {
// If the new $file file has the same owner as $default_file this means
// $default_file is owned by the webserver user. This is an inherent
// security weakness because it allows a malicious webserver process to
// append arbitrary PHP code and then execute it. However, it is also a
// common configuration on shared hosting, and there is nothing Drupal
// can do to prevent it. In this situation, having $file also owned by
// the webserver does not introduce any additional security risk, so we
// keep the file in place. Additionally, this situation also occurs when
// the test runner is being run be different user than the webserver.
if (fileowner($default_file) === fileowner($file) || DRUPAL_TEST_IN_CHILD_SITE) {
$readable = drupal_verify_install_file($file, FILE_READABLE);
$writable = drupal_verify_install_file($file, FILE_WRITABLE);
$exists = TRUE;
}
else {
$deleted = @$file_system->unlink($file);
// We expect deleting the file to be successful (since we just
// created it ourselves above), but if it fails somehow, we set a
// variable so we can display a one-time error message to the
// administrator at the bottom of the requirements list. We also try
// to make the file writable, to eliminate any conflicting error
// messages in the requirements list.
$exists = !$deleted;
if ($exists) {
$settings_file_ownership_error = TRUE;
$readable = drupal_verify_install_file($file, FILE_READABLE);
$writable = drupal_verify_install_file($file, FILE_WRITABLE);
}
}
}
}
// If the $file does not exist, throw an error.
if (!$exists) {
$requirements["{$file} file exists"] = [
'title' => $default_file_info['title'],
'value' => t('The %file does not exist.', [
'%file' => $default_file_info['title'],
]),
'severity' => REQUIREMENT_ERROR,
'description' => t('The @drupal installer requires that you create a %file as part of the installation process. Copy the %default_file file to %file. More details about installing Drupal are available in <a href=":install_txt">INSTALL.txt</a>.', [
'@drupal' => drupal_install_profile_distribution_name(),
'%file' => $file,
'%default_file' => $default_file,
':install_txt' => base_path() . 'core/INSTALL.txt',
]),
];
}
else {
$requirements["{$file} file exists"] = [
'title' => $default_file_info['title'],
'value' => t('The %file exists.', [
'%file' => $file,
]),
];
// If the $file is not readable, throw an error.
if (!$readable) {
$requirements["{$file} file readable"] = [
'title' => $default_file_info['title'],
'value' => t('The %file is not readable.', [
'%file' => $default_file_info['title'],
]),
'severity' => REQUIREMENT_ERROR,
'description' => t('@drupal requires read permissions to %file at all times. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', [
'@drupal' => drupal_install_profile_distribution_name(),
'%file' => $file,
':handbook_url' => 'https://www.drupal.org/server-permissions',
]),
];
}
// If the $file is not writable, throw an error.
if (!$writable) {
$requirements["{$file} file writeable"] = [
'title' => $default_file_info['title'],
'value' => t('The %file is not writable.', [
'%file' => $default_file_info['title'],
]),
'severity' => REQUIREMENT_ERROR,
'description' => t('The @drupal installer requires write permissions to %file during the installation process. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', [
'@drupal' => drupal_install_profile_distribution_name(),
'%file' => $file,
':handbook_url' => 'https://www.drupal.org/server-permissions',
]),
];
}
else {
$requirements["{$file} file"] = [
'title' => $default_file_info['title'],
'value' => t('The @file is writable.', [
'@file' => $default_file_info['title'],
]),
];
}
if (!empty($settings_file_ownership_error)) {
$requirements["{$file} file ownership"] = [
'title' => $default_file_info['title'],
'value' => t('The @file is owned by the web server.', [
'@file' => $default_file_info['title'],
]),
'severity' => REQUIREMENT_ERROR,
'description' => t('The @drupal installer failed to create a %file file with proper file ownership. Log on to your web server, remove the existing %file file, and create a new one by copying the %default_file file to %file. More details about installing Drupal are available in <a href=":install_txt">INSTALL.txt</a>. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', [
'@drupal' => drupal_install_profile_distribution_name(),
'%file' => $file,
'%default_file' => $default_file,
':install_txt' => base_path() . 'core/INSTALL.txt',
':handbook_url' => 'https://www.drupal.org/server-permissions',
]),
];
}
}
// Check the database settings if they have been configured in settings.php
// before running the Drupal installer.
if ($database = Database::getConnectionInfo()) {
$request = Request::createFromGlobals();
$site_path = empty($install_state['site_path']) ? DrupalKernel::findSitePath($request, FALSE) : $install_state['site_path'];
$database = $database['default'];
$settings_file = './' . $site_path . '/settings.php';
$errors = install_database_errors($database, $settings_file);
if (count($errors)) {
$error_message = SiteSettingsForm::getDatabaseErrorsTemplate($errors);
$requirements['database_install_errors'] = [
'title' => t('Database settings'),
'description' => $error_message,
'severity' => REQUIREMENT_ERROR,
];
}
}
}
return $requirements;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.