Initially I had
admin.
subdomain. Now I changed it to
cms.
. Updated nginx rules, reissued certificates. Can load dashboard successfully from new subdomain.
However old subdomain is still appearing in some places - in initial message and in media urls (they are trying to load from
admin.
).
With media thumbnails are obviously not working, but also new ones not uploading and old ones not updating (not allowed to perform this action).
Inside main config file server url is loaded from .env file (updated value there to be new subdomain). And inside media collection config static url is also loaded from .env (just
/media
).
What can be wrong here?
"Not allowed to perform this action" is acutally separate issue. It shows this error for any other collection or global
Or perhaps not separate. If it is reading wrong domain, then it might as well be the reason
I checked multiple times. This variable contains new url. Yet when I build and start server, it says admin panel is available at old url. Does it cache env variables from build to build or something like that?
Well, it looks like that. Starting dev server uses new value, but building and starting prod server uses old value.
@arctomachine Is it possible that your .env file is not getting updated on prod?
A lot of times deployments skip .env files
So it may be reading outdated urls in some cases
That's my first thought
Is there special argument to force reading .env?
Well, I would first check the .env file on your server and see what's in it
Are there any old references?
No, I updated them
Were there prior to me mentioning it?
I updated them at the time of issuing new certificates for this subdomain, so yes
ok so both your dev and prod .env files are consistent
It is one file
what im saying is
the .env file on your local machine has the same contents as the one on your prod machine?
No
hmm
Do you know why?
Because localhost for local and domain name for prod
Hardcoded value works as expected. So the problem is definitely in reading .env
Or can it be that old env variable was loaded into memory and never unloaded again, so config reads it from memory instead of file?
Or is it loading variable from different file? The one that is not .env in root folder?
I found why it happens. It is pm2 preventing update of variables
Ah yes
Happy you figured it out
Only half way. The hard part is to make pm2 respect changes to .env file 😕
@arctomachine pm2 takes a
--update-env
param
that should refresh your env file
Tried that, not working
how are you restarting pm2
when you push to prod
pm2 restart all
?
No, startOrReload --only payload
hmm
generally you would have an ecosystem.config.js
with your app config
Yes, just named differently
ah
then
pm2 restart MYAPP --update-env
That bug was reported in 2014
can you specify the name of the pm2 app explicitly?
Names are defined in ecosystem file
i mean, in the restart command
pm2 restart MYAPPNAME --update-env
Yes, name or id, both work the same
you've tried that
?\
Restart command specifically - no
I would first try that
my second thought is if you specify your env vars in your pm2 config rather than an env file
which seems odd, but is "recommended" by pm2
for instance
module.exports = {
apps : [
{
name: "myapp",
script: "./app.js",
watch: true,
env: {
"NODE_ENV": "development",
}
}
]
}
never tried to do it that way
But first try the restart command
Tried now, same result
OK say you add those env vars to the env object in a pm2 config
Then when you run restart, you pass the changed env var and the flag
that should tell pm2 to replace the env var
kind of weird but worth a try
so you'd end up passing
ENV_VAR=somethingnew pm2 restart app --update-env
and specify ENV_VAR in your env object in your pm2 config
that should update whatever your put as the default in the config file
@arctomachine Let me know if that works, sorry pm2 can be a bit weird
That worked. And subsequent reset without variable works too now
Woot! That's good to know
I'm glad we were able to figure it out
🔥
Let me know if anything else comes up
The rest should work, just this one was new workflow for me
PM2 is a nice, at first it was hard for me, but now I use it for all of my projects on deploy
really nice when you have 2+ things that need restarting
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.