In this article, we are going to change the base URLs of a Magento 2 website, using the swiss army knife for Magento developers, sysadmins and devops i.e. n98-magerun2.
Base URLs can be also changed from the Magento Site backend as well as from the Database using phpMyadmin or Mysql REPL too.
Magento 2, just like magento 1 stores all the crucial configuration in the Database in core_config_data table.
Before configuring the Magento site, make sure web-server (vHost) is configured for the domain/sub-domain and correct DNS records are set.
In our cPanel Server Stack, to add a domain/sub-domain, perform the following steps:
- Login to the cPanel account and search for "Aliases" and click on it.
- To add a domain alias, enter the domain name in the text box.
- Click Add Domain.
- No redirections are required in this case, so click on "Disable Redirection" from the "Manage Redirection" option for the domain alias.
In cPanel Server Stack, there is already n98-magerun2 present on the server, and can be accessed with the command "magento2-cli", yet n98-magerun2 can be easily downloaded via. (wget
Note : Use n98-magerun2/magento2-cli from the document root of the magento 2 site, as the cPanel account user.
To run a magento site on a domain/sub-domain we need to set the required base URLs in the core_config_data table.
Run following command to get the list of already set base URLs
The output will be somewhat similar to
To change the base URL run the commands as shown below
- magento2-cli config:store:set web/secure/base_url https://to.magehost.cloud/
- magento2-cli config:store:set web/unsecure/base_url https://to.magehost.cloud/
Note : Don't forget to clear the caches after making the changes.
Clear the caches with
- magento2-cli cache:clear
- magento2-cli cache:flush
Re-check the base URLs after making changes, the output (magento2-cli config:store:get '%base%url%') will be like
Make sure of the trailing slash '/' at the end of base URLs
Depending on the use cases, there could exist multiple base URLs with different "scope"s and their respective "scope-id"s
In short, There are three scope types - default, websites & stores.