magento change base url code example

Example 1: get base url in magento 2

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$storeManager->getStore()->getBaseUrl();

Example 2: change magento database url usimg musql

UPDATE core_config_data SET value = 'http://www.hypernode.com/' WHERE path LIKE 'web/unsecure/base_url';
UPDATE core_config_data SET value = 'https://www.hypernode.com/' WHERE path LIKE 'web/secure/base_url';

Example 3: magento set base url command line

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

Tags:

Misc Example