Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

commandantp's avatar

URL generated in a queue - localhost returned instead of production server

Hey guys,

Strange, tried to generate a URL in a queue via URL::route('blabla') and outisde of the queue it returns my production server but once inside the queue it returns a localhost server address.

Is that "normal". How can this be fixed?

Thanks!

0 likes
16 replies
Barryvdh's avatar

You can set the app url in the configuration, app.url that's used when running on the console, like with queues.

commandantp's avatar

Hi, thanks for your answer. Strangely enough I did change it on the app.php file however it is still returning localhost when queued. Should I change the queue.php. beanstalkd => 'host' too?

Barryvdh's avatar

Did you set it on the correct environment? Check php artisan env and make sure you have the correct config file.

commandantp's avatar

When on the production server yes I get the right environment. However in Forge I did not set an envrionment variable for the host used in the queue - but I felt like it did not need to be done?

commandantp's avatar

same I just tried setting up in forge an env variable 'debug' with value false, and in the app.php I put up 'debug' => getenv('debug'), but the debug mode is still on....

commandantp's avatar

works with 0 thanks. However still have the url issue...

fideloper's avatar

Sounds like the queue:work --daemon or queue:listen command (whichever you are using) needs the --env flag:

# Depending on which you are using:
queue:work --daemon --env=prod

# or
queue:listen --env=prod

I'm guessing Laravel is finding no env information passed to it, and so is defaulting to whatever your application happens to default to, likely a test/debug environment.

2 likes
noleafclover614@gmail.com's avatar

I set up an environment variable for this so that when deployed via Forge, it uses the server specified there.

// /config/app.php
 'url' => env('APP_URL', 'http://localhost'),
//.env
APP_URL=[domain]
RahulGovind's avatar

I had the same issue when generating urls in the queue and it was fixed after I restarted the queue worker. I guess the source of the problem was that the worker was loaded with the env information from before I changed config/app.php.

concentrico's avatar

@RahulGovind @noleafclover614 What do I need to do for the env variable to take effect? I change my APP URL to my domain and did a php artisan cache:clear but still loading "localhost"

Any suggestions?

niho's avatar

I am having exactly same problem. Changed ENV, changed App/Config Directly, restarted worker, checked environment is correct! Still get localhost! Baffled!

1 like
eric3000's avatar

I am having the same issue with laravel 5.3. Is there some answer ?

natcave's avatar

I was hacking away at this problem for a while now and found an odd occurrence that solved my problem. I'm documenting it here because this post came up as a top search result, so it may help someone else and shave off a few troubleshooting hours.

The urls in my queued emails were not matching the APP_URL variable in my .env file or the url value in my config/app.php file. (Quite frustrating)

I had built a new server on Forge which comes along with a "default" site, then added my "new" site on the same server with a similar .env file. Similar except of course for the APP_URL variable (you may see where this is going).

It turns out, the jobs starting on my "new" site were being picked up by a queue worker on the "default" site, thus plugging in the APP_URL variable set on the default site, which I assume for most people would be "http://localhost".

The solution for me was to simply turn off the queue worker on the "default" site.

So, the lesson here is to check if any other sites on the server are hijacking your queues, therefore plugging in the wrong APP_URL.

Hope this helps someone!

1 like
packy's avatar

Thanks @natcave I just deleted the default scheduler and updated that env file too. Hopefully it works. Seems like an issue that Forge should resolve since its confusing to find that old env url

1 like
AliKazemi's avatar

Hi ,

try php artisan queue:restart after modifying your config(app.url);

Please or to participate in this conversation.