How to migrate Magento 2.0.x from one server to another?

There is a quick reference:

Basically, we need to change the connection config in app/etc/env.php, the url config in core_config_data and set the permission your source files.

--After importing the backup database, we need to change web/unsecure/base_url and web/secure/base_url paths in core_config_data table. We can check:

SELECT * FROM core_config_data a WHERE a.`path` LIKE '%web/unsecure/base_url%'
UNION 
SELECT * FROM core_config_data a WHERE a.`path` LIKE '%web/secure/base_url%'

enter image description here

Change theses values to your own url.

--Should change host, dbname, username, pwd app/etc/env.php:

  array (
    'table_prefix' => '',
    'connection' => 
    array (
      'default' => 
      array (
        'host' => 'localhost',
        'dbname' => 'mage21',
        'username' => 'root',
        'password' => '',
        'active' => '1',
      ),
    ),
  ),

--Change the permission and owner of files:

http://devdocs.magento.com/guides/v2.1/install-gde/prereq/file-sys-perms-over.html

http://devdocs.magento.com/guides/v2.1/config-guide/prod/prod_file-sys-perms.html

--May run static content deploy php bin/magento setup:static-content:deploy

--Remember to clear Magento Cache and delete var/generation, var/composer_home, var/view_preprocessed.

There is a good doc here: http://devdocs.magento.com/guides/v2.0/config-guide/prod/prod_deploy.html

[EDIT]

From the Magento 2.2 version, there are many improvements: http://devdocs.magento.com/guides/v2.2/config-guide/deployment/


First off all see that the database is exported to the new server.

Then transfer the magento root files to the new server.

In the root folder, change to the new database. You can do this by going to app/etc/env.php and changing the DB array information. change the host, dbname, username and password to the new one.

Then you change you secure and unsecure URLs in the magento DB core_config_data to the new IP, don't forget the "/" after your IP, it's required.

Make the web user owner of the new file ( for apache it's: sudo chown -R www-data /var/www/magentoroot ). Set the correct file and folder permissions.

Finally clear the cache by running bin/magento cache:clean and bin/magento cache:flush.