Magento 2: change the base-url using the command line

The following Magento 2’s CLI command will update the Magento base-url and the base-url-secure values.

Go to the Magento’s root directory, then type within the console:

php bin/magento setup:store-config:set --base-url="http://localhost:8080/"

Replacing http://localhost:8080/ with your new base-url.

You may want to change the base-url-secure also:

php bin/magento setup:store-config:set --base-url-secure="https://localhost:8080/"

Note: both base-url and base-url-secure values must contain the URL’s scheme, http:// or https://, and a trailing slash /.

Then clear the cache:

php bin/magento cache:flush

Troubleshooting

Clear current values from the database

Can happen that the above command doesn’t works as expected and you still have some url pointing to the old base-url. In these cases you have to clear some values in your db.

Open the Magento 2 database with your favorite MySQL tool then go to the core_config_data table.

Search for rows having these values in the column path (note that there could be more than one row for each value):

  • "web/unsecure/base_url"
  • "web/secure/base_url"

Delete these rows (Magento will recreate them).

Now you can set the base-url value using the above CLI command.

Single-Store Mode option enabled

If you have the Single-Store Mode option enabled this could bring to some problem with setting the base-url with the command line.

In this case you should modify the base-url using only the command line and not the Magento’s Admin Panel. If you already saved the Base url field value using the Admin Panel you should clear values within the Magento’s core_config_data table as described above.

References

http://devdocs.magento.com/guides/v2.0/install-gde/install/cli/install-cli-subcommands-store.html
http://stackoverflow.com/questions/4280049/how-can-i-fix-the-unsecure-base-url-on-my-magento-installation
http://stackoverflow.com/questions/5177362/how-to-change-the-base-url-in-magento-because-my-site-were-gone-after-im-chang
http://magento.stackexchange.com/questions/39752/how-do-i-fix-my-base-urls-so-i-can-access-my-magento-site

Categories

Category BootstrapCategory CoffeescriptCategory DrupalCategory GravCategory HTMLCategory JavascriptCategory JoomlaCategory jQueryCategory LaravelCategory MagentoCategory PHPCategory SharePointCategory SpringCategory ThymeleafCategory WordPressCategory Workflow

Comments

Developed and designed by Netgloo
© 2016 Netgloo