What is the proper procedure to change APP_URL of an existing shopware 6.5.1.1?

As in the subject. I’ve been doing some local development on my PC running shopware in docker. I’ve set up my /etc/hosts to point my target domain to 127.0.0.1 and I’ve set up the shop license domain in Settings->Account correctly (to my target domain). But I forgot to set my APP_URL unfortunately. I’ve installed and uninstalled a free app in the meantime. I would like to change that APP_URL from localhost to my target domain, but if I do that I can’t reinstall that free app, because it complains:

[Shopware\Core\Framework\App\Exception\AppRegistrationException]             
  The app url changed. Please resolve how the apps should handle this change.

I had a look at the code and I found this config property that contains the previous APP_URL:
core.app.shopId

So when I run
bin/console system:config:get core.app.shopId
It indeed comes back with:

http://localhost
XXXXXXXXXXXXXXX

Can I simply delete this config value or update it? Will it break more stuff? I have added a lot of data to this install so I’d rather not break it.

I also found in the code this snippet in ShopIdProvider.php

if (EnvironmentHelper::getVariable('APP_URL') !== ($shopId['app_url'] ?? '')) {
            if ($this->hasApps()) {
                /** @var string $appUrl */
                $appUrl = EnvironmentHelper::getVariable('APP_URL');

                throw new AppUrlChangeDetectedException($shopId['app_url'], $appUrl);
            }

            // if the shop does not have any apps we can update the existing shop id value
            // with the new APP_URL as no app knows the shop id
            $this->systemConfigService->set(ShopIdProvider::SHOP_ID_SYSTEM_CONFIG_KEY, [
                'app_url' => EnvironmentHelper::getVariable('APP_URL'),
                'value' => $shopId['value'],
            ]);
        }

This appears to suggest my APP_URL should be updateable as long as there are no apps installed, but that is not the case. I had no installed apps when I changed APP_URL, and then I only get the error when I try to install a free app.

Does anyone have any ideas?

I may as well reply to myself as I found a method that works. Perhaps it helps someone.

To „fix“ The APP_URL is wrong error/issue one just needs to uninstall all apps (check your custom/apps folder as you may be unaware one of free „plugins“ is actually an app - that was one day of my issues, one of the extensions that called themselves plugin was in fact an app).

Once no apps are installed at all, you can change your APP_URL and upon reinstall of any app shopware 6 core should update its core.app.shopId config entry with the new url and old shopId key/random string.

However, depending on an app, it may not like seeing the same shop id string with a new APP_URL so it is possible to generate a new one by removing the old one altogether.

For this I’d recommend all apps to be uninstalled and your shopware account logged out, switch off incoming traffic, PHP and your web service, then go to the SQL dB and find the core.app.shopId in the system config table. Make a copy of the value just in case (better have a backup of the whole thing) and replace the value with an empty json so „{}“.

Then start your PHP and web services, allow web traffic for yourself only, login to admin interface and by the time you load my extensions it should’ve generated a new shop id with your new APP_URL. Now you can log back in to shopware account and reinstall apps. They might even work now!

Ran into the same issue.
As I had some configured apps already installed I did not want to deinstall all of them.

Note: I changed the APP_URL prior to installing any app. So the already installed apps did not care about the missmatch in the condig (I guess…).

I assured that the APP_URL is set in the env.local file.
Then I ran this command:

bin/console system:config:set core.app.shopId https://yourUrl.com

Then the app was able to be installed.

If you don’t know what this is doing, please do not use this as a recommendation.
I don’t know if it has any side effects → I did not notice any yet but be warned!