Migrate Magento 2 from One Server to Another Migrate Magento 2 from One Server to Another

Sometimes you need to save the copy of your Magento E-commerce store at another place just as a form of insurance against data loss. Migrating a Magento 2 store to the new server is a simple task and it requires just a basic knowledge of PHP and Magento 2. This tutorial will show you how you can completely migrate your Magento 2 store from one server to another.

1. Export Magento 2 Database

By default, you may have PHPMyAdmin or a similar tool that is capable of exporting your database, included in the cPanel/Platform of your server. Open your database tool and export your Magento 2 database in the .sql file format, because most of the database tools support the .sql file.

2. Backup and Transfer Magento 2 Files & Folders

After exporting your database, now you will need to download all files & folders of Magento 2 from your current server and upload them to the new server. It might be a time-consuming task, as it depends on how big your Magento 2 store is. If possible, a good approach is to create a zip archive of the files & folders before downloading them.

Using your server’s file manager, go to Magento 2 installation directory, create a zip archive of all the files & folders and then download it.

Upload the downloaded zip file to the new server and extract it to the new desired destination folder for the Magento 2 installation on the new server.

3. Import Magento 2 Database

Once you have transferred the Magento 2 files & folders, you should import the database to the new server. Go to the PHPMyAdmin or any similar database tool of your new server. Create a new database. Assign credentials to the database or create new username and password for it. In step 1, as we had already exported the database, import the database .sql file into this new database.

4. Edit Magento 2 Configurations

We are done with exchanging files between both the servers. Now it’s the time to configure your Magento 2 store with your new server. First, you need to edit the app/etc/env.php file with new Magento 2 database configurations according to your new server. Open the env.php file using your server’s file manager and alter the lines below:


 ‘db’ =>

 array (

   ‘table_prefix’ => ”,

   ‘connection’ =>

   array (

     ‘default’ =>

     array (

       ‘host’ => ‘DATABASE_HOST’,

       ‘dbname’ => ‘DATABASE_NAME’,

       ‘username’ => ‘DATABASE_USERNAME’,

       ‘password’ => ‘DATABASE_PASSWORD’,

       ‘active’ => ‘1’,






‘host’ is the database hostname. Most commonly used host is “localhost”.

‘dbname’ is the database name. Use the one you had created in step 3.

‘username’ is a username that has full privileges to your new database.

‘password’ is the password for that particular database user.


New server means new domain name. You have to replace old server domain name with new domain name.  For this, you need to modify the value of web/unsecure/base_url and web/secure/base_url in core_config_data table. Enter the new domain name in the value column for both records.

5. Clear Magento 2 Cache

The final step is to clear the Magento 2 cache. You can do this by deleting everything from var/cache inside your Magento 2 directory, or you can use the CLI Command below:


PHP bin/magento cache:flush


That’s all you need to do. Your Magento 2 store should now be running properly on the new server. Have any questions? Feel free to ask me in the comments section below.


About Author

Fayyaz Khattak is the Magento Community Manager at Cloudways – a managed Magento Cloud Hosting Platform. His objective is to learn & share about PHP & Magento Development in Community. He loves food and driving.Stay Connected: Email him at m.fayyaz@cloudways.com or you can follow him on Twitter.

No comments so far.

Be first to leave comment below.