Solution with Symfony-5.4
Generating URLs in commands works the same as generating URLs in services. The only difference is that commands are not executed in the HTTP context. Therefore, if you generate absolute URLs, you'll get http://localhost/
as the host name instead of your real host name.
The solution is to configure the default_uri
option to define the "request context" used by commands when they generate URLs:
On config/packages/routing.yaml add the URL of the real host.
# config/packages/routing.yaml
framework:
router:
# ...
default_uri: 'https://example.org/my/path/'
The default_uri option was introduced in Symfony 5.1.
For reference please see the official documentation.
https://symfony.com/doc/5.4/routing.html#generating-urls-in-commands