"Warning: file_exists(): open_basedir restriction in effect" when trying to install new modules on Drupal 8.x

If you are using shared hosting, service provider may restrict the right to access the top-level directory.

1.Modify the function mkdir as following at "/core/lib/Drupal/Core/File/FileSystem.php"

if ($recursive) {
  // Ensure the path is using DIRECTORY_SEPARATOR, and trim off any trailing
  // slashes because they can throw off the loop when creating the parent
  // directories.
    $uri = rtrim(str_replace('/', DIRECTORY_SEPARATOR, $uri), DIRECTORY_SEPARATOR);
    // Determine the components of the path.
    $components = explode(DIRECTORY_SEPARATOR, $uri);
    // If the filepath is absolute the first component will be empty as there
    // will be nothing before the first slash.
    if ($components[0] == '') {
      $recursive_path = DIRECTORY_SEPARATOR;
      // Get rid of the empty first component.
    else {
      $recursive_path = '';
   // Don't handle the top-level directory in this loop.
   // Create each component if necessary.

   foreach ($components as $component) {
     $recursive_path .= $component;
         $recursive_path .= DIRECTORY_SEPARATOR;
     if (!file_exists($recursive_path)) {
      if (!$this->mkdirCall($recursive_path, $mode, FALSE, $context)) {
        return FALSE; 

      // Not necessary to use self::chmod() as there is no scheme.
      if (!chmod($recursive_path, $mode)) {
         return FALSE;
     $recursive_path .= DIRECTORY_SEPARATOR;