ddev: Don't manage Craft 3 .env, Fix `*_SITE_URL`
The recently added settings management for Craft projects broke my ddev / Craft 4 project - when I came back to it after some time away - and in a way I couldn’t immediately understand from this error:
Failed to start craft-dev: template: templateStringToFile:/home/jeremy/ddev-projects/c4-dev/.env:7: function "siteUrl" not defined
Prior to this the project was working fine for a few months, it was only on coming back to it that the new settings management kicked in, with a ddev upgrade.
Thus, I think disable_settings_management
should definitely default to false
for existing projects.
As per the other issue discussion, I think PRIMARY_SITE_URL
should be added only if the existing & typical CRAFT_SITE_URL
is not already present - otherwise it’s just doubling up right?
The config setting is the default way to define this in Craft: https://craftcms.com/knowledge-base/how-craft-determines-the-site-url https://craftcms.com/docs/2.x/config-settings.html#siteurl
And thus, with Craft 4’s new approach to .env variables, CRAFT_SITE_URL
is the de facto default way of actually implementing this.
Personally I am not super fussed about Mailhog, other than to note that Craft has a config setting for a similar thing already: https://docs.craftcms.com/v3/config/config-settings.html#testtoemailaddress
'testToEmailAddress' => (\craft\helpers\App::env('SEND_ALL_EMAILS_TO')) ?? null,
So in Craft’s case, Mailhog is likely to be irrelevant to most and I would expect that to be set as a matter of course in .env
files for dev environments.
_Originally posted by @bossanova808 in https://github.com/drud/ddev/issues/4552#issuecomment-1429132626_
(Adding as a new issue per request)
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 19 (9 by maintainers)
Commits related to this issue
- refactor: detect Craft CMS version and warn user on type mismatch, fixes #4650 — committed to gilbertsoft/ddev by gilbertsoft a year ago
- refactor: detect Craft CMS version and warn user on type mismatch, fixes #4650 — committed to gilbertsoft/ddev by gilbertsoft a year ago
- refactor: detect Craft CMS version and warn user on type mismatch, fixes #4650 — committed to gilbertsoft/ddev by gilbertsoft a year ago
Ok great, thanks for weighing in! So it sounds like we should ditch any mention of
PRIMARY_SITE_URL
orCRAFT_SITE_URL
, and run with this instead…For Craft 4, of course. None of these would be applied to a Craft 3 site.
Correct me if I’m mistaken @timkelty!
I’m not a
composer
expert, but I saw @khalwat mention this on Discord…Would that help us determine the current version of Craft?
Looks like this command returns a JSON of the package data from the
composer.lock
file…Sorry for the late response! You (accidentally) raise a good philosophical question @rfay…
Should these two environment variables even be set in a local environment?
I lean towards “yes”, for the following reasons:
url
) which attempt to use these values if they exist..env
file. It’s pretty common to copy an.env
file between environments, then simply change the relevant values.As usual, I’ll defer to Tim (or another authority) if I’m mistaken about any of this!
This isn’t quite right. There is in fact, no “standard” for this variable, because in Craft 4 there is no
siteUrl
config setting (because multi-site). Setting this env wouldn’t magically do anything unless you manually referenced it in your site’s URL. In that regard, naming itCRAFT_*
is actually a bit misleading.@lindseydiloreto this is exactly what I would suggest. Since a DDEV install is always going to “single-site” by default, setting these in env allows you to just set your primary site’s URL to
@web
and you’re all set.