Magento 2: Why is rebuilding config.php from CLI failing with 'Invalid Base URL'?
-
12-03-2021 - |
Frage
To set the background I am using Magento 2.3.0 and have imported (successfully so far) data from an existing multi-store site. I now can't access either the front end or the admin area of the site since the config has now changed and Magento throws an Exception requesting I rebuild config.php
. The problem started when I changed a config key from the command line (the admin frontend URL).
Now when I try to rebuild /etc/config.php using
php bin/magento app:config:import
I receive the error
Import failed: Invalid Base URL. The value must be a URL or one of the placeholders: {{base_url}}
... which incidentally is a pretty feeble error message as it doesn't even indicate which key is causing the problem.
After stepping through the code I can see one of the offending keys is web/unsecure/base_web_url
for the default
scope which is causing the problem since in Magento 2 core post config read processing it is returning http:///
which clearly is an invalid URL. This is despite the fact that in my database (in core_config_data) there is an entry for that path and scope with a valid URL (which does end with a trailing /).
Stepping deeper into the code I can see the problem is that module-store/Model/Config/Placeholder
is calling /App/Request/Http->getDistroBaseUrl()
which uses the PHP Server variable ['HTTP_HOST']
to determine the host which is blank when called from the command line and hence returns the http:///
.
If anyone can shed any light on how this can be resolved I'd be very grateful.
Lösung
Similar issue in the past was all down to cache in your CLI run the following
rm -rf var/cache/ generation/
After you have done the above run
php bin/magento setup:upgrade && php bin/magento setup:static-content:deplpoy
You may need to force the deployment process you can do that by adding -f to the end over the second command
after which worked fine make sure that parameter is set and valid in the database before as config is cached in magento 2