How do I move Magento 2 to a new server?

How do I move Magento 2 to a new server?
How do I move Magento 2 to a new server?

Here is some main step to move Magento 2 to a new server? There might be additional things: changing domains, DNS, PHP-Configuration, tools & programs on your server.

1. Backup files in your Magento directory on your old server:

You might empty your var/cache, var/session, var/report, and var/log directory before to save space and speed up the backup.

2. Create a database dump on your old server:

Use phpMyAdmin, Chive, or via console with mysqldump

3. Set up the directory structure for files and create database + user on your new server

Create new folder and point your domain to this folder and create new database.

4. Move files and database dump to your new server: via FTP, SSH,...

5. Extract file-backup to your new Magento directory

6. Check and set file-permissions

Usually 644 for files and 755 for folders.

7. Import database-dump on your new server:

Use phpMyAdmin, Chive or via console with MySQL

8. Update new database settings in app/etc/env.php

You can change new information of new database in ‘db’ part.

9. Update URLs in core_config_data:

You can edit the base_url via Web-Frontend (phpMyAdmin, Chive,…) or use these SQL-statements. You need to edit the URLs for your stores also.

Look for path =”web/unsecure/base_url” and path=”web/secure/base_url” in the core_config_data table.

10. Empty var/cache, var/session, var/report, var/log (if you did not do that before you created the backup on the old server)

11. Reindex your data: catalog url rewrites

You can reindex your data by command line:

php bin/magento indexer:reindex

then you can check your website again to make sure all work fine.