Why drupal_realpath('public://') returns an incorrect path?
drupal_realpath() has been deprecated and shouldn't be used; since you have a stream wrapper URI you should be able to get the correct path like this:

$uri = 'public://';
if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) {
  $path = $wrapper-&gt;realpath();
}


Also make sure that your public path is correct in the UI (at admin/config/media/file-system)