Q: When I run
drush statuson production, it shows the generated URL instead ofmy.domain.comThis means that links in emails generated by the system during crons and other tasks like sitemap generation or logging are using the wrong URL.
How to tell the system to use the public URL?
A: This is a pretty common issue when running drush in any firewalled or routed-to environments. Drush running from the CLI doesn’t natively know what the appropriate hostname is.
We’ve supplied a small fix to support this for you with the utility script platformsh-templates/drupal8: drush/platformsh_generate_drush_yml.php. This fix pulls your routing information from the Upsun environment and makes it available to drush via a config file that drush uses.
If you’ve based your build on the Drupal 8 or 9 template, it should already be there. If you imported your project yourself, you probably need to check that the file is there, and that the line in the deploy hook that invokes it is also there.
hooks:
deploy: |
php ./drush/platformsh_generate_drush_yml.phpTo verify, check your deploy log to confirm that it ran cleanly:
upsun log deploy
... Created Drush configuration file: /app/.drush/drush.yml
And check the file .drush/drush.yaml in the built environment to see that it worked.
upsun ssh "cat /app/.drush/drush.yml"
# Drush configuration file. # This was automatically generated by the script: # /app/drush/platformsh_generate_drush_yml.php options: # Set the default site URL. uri: "https://my.site.com/"
When it works, a simple drush status should be enough to confirm that the URL is being correctly detected by the Drupal internals.
upsun drush status
Drupal version : 9.0.2 Site URI : https://my.site.com/
In drush versions prior to (about?) 8.6, it used drushrc.php instead of drush.yml, and this helper script will not help if you’ve got drush older than that. Updating drush to something newer than 2017 should help.
Although it’s possible to force drush to use the correct URL by passing it the --uri= parameter every time, this is not a portable solution to hard-code into your .upsun/config.yaml file, as it will now always be incorrect in your development branches. Don’t do that. Use the environment settings to supply your route URL instead.
Comments
Please sign in to leave a comment.