What gets moved?
Magento is software for running an online shop. A Magento store has two parts. The first is the files: the code, themes and product images. The second is the database, which is like a big filing cabinet that holds products, customers and orders. You must move both.
Warning: do not switch off your old server until the new one works. Keep the old copy as a backup.
Steps
- On the old server, put the store in maintenance mode so no new orders arrive during the move:
php bin/magento maintenance:enable
Run this from your Magento folder. It shows visitors a "back soon" page.
- Make a copy of the files. Compress the Magento folder into one archive:
tar -czf magento-files.tar.gz /path/to/magento
This packs the whole folder into one small file. Replace the path with your own.
- Export the database:
mysqldump -u DBUSER -p DBNAME > magento-db.sql
This saves all your store data into a text file. Replace DBUSER and DBNAME with your own. Your old app/etc/env.php file shows them.
- Copy both files to the new server. You can use SFTP, or the
scpcommand. - On the new server, create an empty database and a database user with full rights to it. You can do this in your control panel under MySQL Databases.
- Import the data into the new database:
mysql -u NEWUSER -p NEWDB < magento-db.sql
- Unpack the files into the new web folder:
tar -xzf magento-files.tar.gz
- Open
app/etc/env.phpand update the database name, user and password to the new ones. - If your domain changes, update the base URLs in the
core_config_datatable. - Clear the cache and fix file permissions:
php bin/magento cache:flush
php bin/magento indexer:reindex
The first command clears stored copies of pages. The second rebuilds the search and price tables.
- Test the store using a temporary link or your computer's hosts file.
- When all works, point your domain's DNS to the new server. DNS is the internet's phone book that tells browsers where your site lives.
- Turn maintenance mode off:
php bin/magento maintenance:disable
Quick recap
- Move both the files and the database.
- Use maintenance mode while you copy.
- Update env.php on the new server.
- Test first, then change DNS.