I am trying to get the base url of the drupal 8 website in a queue process but I am getting http://default as the base url. What am I missing here?

  public function testUrl() {
    global $base_url;
    $host = \Drupal::request()->getSchemeAndHttpHost();
    var_dump($host); // output - http://default
    $host2 = \Drupal::request()->getHost();
    var_dump($host2); // output - default
    $uri = \Drupal::request()->getUri();
    var_dump($uri); // output - http://default
    $url = \Drupal\Core\Url::fromUserInput('/', ['absolute' => TRUE])->toString();
    var_dump($url); // output - http://default
    $url_options = [
      'absolute' => TRUE,
      'language' => \Drupal::languageManager()->getCurrentLanguage(),
    $site_url = \Drupal\Core\Url::fromRoute('<front>', [], $url_options)->toString();
    var_dump($site_url); // output - http://default
    var_dump($_SERVER['SERVER_NAME']); // output - NULL

1 Answer 1


The process running the queue worker will be setting that default host. For example, drush cron

You may need to set the public host name with the drush request, via uri or use a drush alias.

drush --uri=http://example.com cron

More info https://docs.drush.org/en/8.x/usage/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.