How to change base URLs in Magento 2

Using Command line

NOTE: Only use this method if you know the command line and MySQL queries.

NOTE: Angled brackets (<>) indicate placeholder information. Replace the brackets and everything between them with the stated information.

Use SSH to log in to the server hosting the Magento installation’s database.

Within Magento’s root directory run the below commands:

mysql -u <database_user> -p

Enter your password when prompted.

Access their database using the following command:

use <database_name>;

Execute:

SELECT * from core_config_data where path like '%base%url%';

This will display the current base_urls set in Magento 2.

To change the base URLs, execute:

Set Unsecure URL

UPDATE core_config_data set value = 'http://domainname/' where path = 'web/unsecure/base_url';

Set Secure URL

UPDATE core_config_data set value = 'http://domainname/' where path = 'web/secure/base_url';

Using phpMyAdmin

Instructions are for a simple “one store” website where the “default store view” is set to inherit its setup from the “default config”. There will be an additional instance of the below mentioned table rows for each unchecked Use Website checkbox.

Open your core_config_data table in phpMyAdmin.

Sort table by path column and find the following rows for your unsecure section, they should look like the following:

Columns

PATH                         VALUE
web/unsecure/base_url        http://www.example.com/
web/unsecure/base_link_url   {{unsecure_base_url}}
web/unsecure/base_skin_url   {{unsecure_base_url}}skin/
web/unsecure/base_media_url  {{unsecure_base_url}}media/
web/unsecure/base_js_url     {{unsecure_base_url}}js/

Replace http://www.example.com/ with your appropriate domain url (trailing slash necessary) and if you’ve installed in a subfolder append it with a / after it.

Find the following rows for your secure section, they should look like the following:

Columns

PATH                        VALUE
web/secure/base_url         https://www.example.com/
web/secure/base_link_url    {{secure_base_url}}
web/secure/base_skin_url    {{secure_base_url}}skin/
web/secure/base_media_url   {{secure_base_url}}media/
web/secure/base_js_url      {{secure_base_url}}js/

Replace https://www.example.com/ with your appropriate domain url (trailing slash necessary) and if you’ve installed in a subfolder append it with a / after it. If you haven’t received your security certificate and enabled TLS/SSL yet, use http instead of https

Clear contents from var/cache, var/session directories after changing base_urls.

Clearing cache and sessions is necessary because your config is cached and clearing it forces a reread of the configuration data from the core_config_data table and reestablishment of sessions with the proper information.

Leave a Reply