Magento Setup – How the ‘magento setup:store-config:set –base-url’ Command Works

adminbase-urlcliconfigurationmagento2

I was thinking that such command was the same as setting the Base url from the Magento admin panel, from Configuration / Store / Web / Base Urls, but after some try it seems it is not the same.

When I set the Base url field from the Magento's Admin Panel, it writes this row inside the core_config_data table, with scope = default:

| scope   | path                   | value                 |
-----------------------------------------------------------|
| default | web/unsecure/base_url  | <base-url-value>      |

When I set the base-url with the CLI:

magento setup:store-config:set --base-url "<new-value>"

it deletes the previous row and adds another row, with scope = websites

| scope    | path                   | value                 |
------------------------------------------------------------|
| websites | web/unsecure/base_url  | <new-value>           |

Now, if I go back to the admin panel, I don't see the new value but I see a default value {{base_url}} within the Base url field.

Finally if I set again the value from the Magento's Admin Panel and I save it, it creates another row inside the table with scope = default. And from now I could have two rows with two different base-url inside the database (and I'm a bit worried about this).

Since setting the wrong base-url could make the website unavailable, I would like to have things clear in mind.

What is the difference between these two methods and what is the proper way to set the base-url for a simple Magento e-commerce with only one store?

I can guess it have something to do with multi-store configurations, but I still do not understand how..

Also, is there not a command line to set the base-url with scope = default (as I was setting it from the admin panel)?


The Magento's documentation doesn't help me very much:

–base-url

Base URL to use to access your Magento Admin and storefront in any of the following formats:

  • http[s]://[host or ip]/[your Magento install dir]/. Note: The scheme (http:// or https://) and a trailing
    slash are both required. [your Magento install dir] is the
    docroot-relative path in which to install the Magento software.
    Depending on how you set up your web server and virtual hosts, the
    path might be magento2 or it might be blank. To access Magento on
    localhost, you can use either http://127.0.0.1/[your Magento install
    dir]/ or http://127.0.0.1/[your Magento install dir].

  • {{base_url}} which represents a base URL defined by a virtual host setting or by a
    virtualization environment like Docker. For example, if you set up a
    virtual host for Magento with the host name magento.example.com, you
    can install the Magento software with –base-url={{base_url}} and
    access the Magento Admin with a URL like
    http://magento.example.com/admin.

Still I don't get where is the difference with the Admin Panel's Base url field.

Best Answer

I can guess it have something to do with multi-store configurations, but I still do not understand how..

It seems that you turn on 'Enable Single-Store Mode' option (Stores / Configuration / General / Single-Store Mode / Enable Single-Store Mode = Yes).

In this case, if you set the Base URL value using Magento CLI, it will be saved with 'websites' scope. If you turn this option off, the Base URL value will be saved with 'default' scope.

Not sure, but it seems that there is no way to set the scope, when you save the config data using Magento CLI.