Change a Magento Domain Name

Table of Contents

Introduction

Learn how to change the domain name (URL) of a Magento installation. This is helpful if you wish to migrate a Magento store to a new domain name, or change the base URL of the Magento store.

Requirements

  • A 1&1 Cloud Server with Magento installed

For step-by-step instructions on installing Magento, see our article Install Magento on a Linux Cloud Server with Ubuntu 16.04.

Edit the Database

Note: Before you begin this process, we recommend you set a restore point by creating a Server Snapshot from your Cloud Panel. If a problem occurs, this will allow you to "roll back" your server to the point at which you created the Server Snapshot.

For more information on creating and managing Server Snapshots, see our 1&1 Cloud Server documentation on the topic.

To change the Magento installation's URL, you will first need to update two values in the Magento database's core_config_data table:

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

Connect to the server with SSH, then log in to MySQL:

mysql -u root -p 

Switch to the Magento database:

USE [database name];

For example, to edit a Magento database named my_magento the command is:

USE my_magento;

Update the Unsecure URL

View the existing values for the web/unsecure/base_url field:

 SELECT config_id, path, value FROM core_config_data WHERE path = "web/unsecure/base_url";

MySQL will respond with:

+-----------+-----------------------+-----------------------+
| config_id | path                  | value                 |
+-----------+-----------------------+-----------------------+
|         2 | web/unsecure/base_url | http://example.com/   |
+-----------+-----------------------+-----------------------+
1 row in set (0.00 sec)

The command to update this value is:

UPDATE core_config_data SET value = "[New URL]" WHERE config_id = [config ID];

For example, to change the example above, the command is:

UPDATE core_config_data SET value = "http://store.example.com" WHERE config_id = 2;

MySQL will respond with:

Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

You can verify the change with the command:

 SELECT config_id, path, value FROM core_config_data WHERE path = "web/unsecure/base_url";

MySQL will respond with:

+-----------+-----------------------+---------------------------+
| config_id | path                  | value                     |
+-----------+-----------------------+---------------------------+
|         2 | web/unsecure/base_url | http://store.example.com/ |
+-----------+-----------------------+---------------------------+
1 row in set (0.00 sec)

Update the Secure URL

View the existing values for the web/secure/base_url field:

 SELECT config_id, path, value FROM core_config_data WHERE path = "web/secure/base_url";

MySQL will respond with:

+-----------+---------------------+------------------------+
| config_id | path                | value                  |
+-----------+---------------------+------------------------+
|         3 | web/secure/base_url | https://example.com/   |
+-----------+---------------------+------------------------+
1 row in set (0.00 sec)

The command to update this value is:

UPDATE core_config_data SET value = "[New URL]" WHERE config_id = [config ID];

For example, to change the example above, the command is:

UPDATE core_config_data SET value = "https://store.example.com" WHERE config_id = 3;

MySQL will respond with:

Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

You can verify the change with the command:

 SELECT config_id, path, value FROM core_config_data WHERE path = "web/unsecure/base_url";

MySQL will respond with:

+-----------+---------------------+---------------------------+
| config_id | path                | value                     |
+-----------+---------------------+---------------------------+
|         3 | web/secure/base_url | https://store.example.com |
+-----------+---------------------+---------------------------+
1 row in set (0.00 sec)

Exit MySQL:

quit;

Flush the Cache

In a browser window, log in to the Magento admin panel. Click System > Cache Management.

Change Magento URL

Click Flush Magento Cache.

Change Magento URL

This will flush the old domain name settings, and redirect you to the new Magento admin panel URL.

Comments

Tags: Magento