Magento migration: move your shop to a new server

Table of Content

Magento mirgation: move your shop to a new server

As time moves on and your business grows, there may be a need to move your Magento store to another server. For example, you need an upgraded server, or you just don’t like the level of service of your hosting company, or you want to extend your platform functionality with infinite scroll and other add-ons and ensure it performs smoothly. Whatever the reasons of Magento migration are, moving a functioning store is not the easiest task and you may face various challenges while performing it.

This article describes how to move Magento 2 to another server in detail, and I really hope it’ll help you avoid some typical mistakes of Magento migration to another server.

Prepare to move your store

Before doing anything, go and check if the new server suits the minimal Magento requirements. It is possible you may need to set up your PHP or install the extensions missing. Also, make sure you have enough disk space on the new server; it should be okay to store the whole shop plus you need some spare space.

Store’s backup and copy

We always warn our clients so they won’t make rush decisions. Remember: always test your changes so they won’t harm your Magento shop or interrupt the cash flow.

Switch the domain to the new server only when you’re absolutely sure the shop is working just fine (and you’ll need to sync the data before the final switch).

We have already checked our new server and made sure it suits all the requirements, and now we are ready to move on!

Create a website and a database for your Magento shop.

After that create a backup copy for files and the database. To make the size of the backup copy smaller, exclude var/cache, var/full_page_cache, var/log, var/report, var/session.

[php]cd /home/mageold/public_html
tar -czf ~/magento-files.tar.gz --exclude=var/cache --exclude=var/full_page_cache --exclude=var/log --exclude=var/report --exclude=var/session .
mysqldump -h localhost -u mageold_magento -p mageold_magento | gzip > ~/magento-db.sql.gz[/php]

Use a convenient way to transfer the backup files to the new server. We suggest SCP:

[php]scp ~/magento-files.tar.gz ~/magento-db.sql.gz magenew@newhost:[/php]

Now you need to unpack the backup copy on the new server:

[php]tar -xzf ~/magento-files.tar.gz -C /home/magenew/public_html
gzip -dc ~/magento-db.sql.gz | mysql -h localhost -u magenew_magento -p magenew_magento[/php]

Install the transferred Magento backup files

Edit app/etc/local.xml and add the new database settings to it. If you need that, change access permissions. There are two variants:

  1. The web server runs scripts on behalf of the user which is the owner of the files (magenew)
  2. The web server runs scripts on behalf of a separate user (www-data)

For variant 1 you need to set the permissions like this:

[php]find /home/magenew/public_html -type f -print0 | xargs -r0 chmod 640
find /home/magenew/public_html -type d -print0 | xargs -r0 chmod 750[/php]

Allow the web server to save the files it doesn’t own for the second variant:

[php]find /home/magenew/public_html -type f -print0 | xargs -r0 chmod 644
find /home/magenew/public_html -type d -print0 | xargs -r0 chmod 755
chmod -R a+w /home/magenew/public_html/{app/etc,media,var,includes}[/php]

Test your moved Magento shop

As your domain is still pointing at the old server, add this line to the hosts file (/etc/hosts for unix-like systems and %SYSTEMROOT%\system32\drivers\etc\hosts for Windows-like ones):

[php]1.2.3.4 yourdomain.com[/php]

Where 1.2.3.4 is your new server IP address and yourdomain.com is the domain attached to your Magento shop. Don’t forget to delete this line from the hosts file after the test.

Now it’s time for a big test! Carefully check how the transferred shop is working. Imitate users’ behavior to check if the process of shopping is going smoothly. This is the crucial step of migrating to the new server.

Sync data before full migration

If you didn’t find any errors on the previous step or fixed them all, it’s time to sync your data. Please keep in mind these two important points while completing the process of moving Magento to a new server:

  • DNS settings can’t be updated instantly, so switch your domain TTL time for the smallest available beforehand. Don’t start the final stage of migrating before the old TTL time expires.
  • While you sync your data, the shop on your old server should be off.

To switch the old store server off, turn cron off and enable maintenance mode at touch /home/mageold/public_html/maintenance.flag.

Now it’s time to sync the data. To speed the process we advise to use rsync.

[php]rsync -avz --delete -exclude=var/cache --exclude=var/full_page_cache --exclude=var/log --exclude=var/report --exclude=var/session --exclude=app/etc/local.xml /home/mageold/public_html/ magenew@newhost:/home/magenew/public_html/
mysqldump --add-drop-table -h localhost -u mageold_magento -p mageold_magento | gzip > ~/magento-db.sql.gz
scp ~/magento-db.sql.gz magenew@newhost:[/php]

Now upload the database to the new server.

[php]gzip -dc ~/magento-db.sql.gz | mysql -h localhost -u magenew_magento -p magenew_magento[/php]

Access permissions may be changed during the synchronization – make sure you check or restore them.
Clear Magento cache:

[php]rm -fr /home/magenew/public_html/var/{cache,full_page_cache,log,report,session}[/php]

Last stage of Magento migration

Almost done! Turn cron tasks on for the new server and change DNS setting so the domain points to the new server. As TLL time expires, traffic will be directed to the new server.

Please note that the old shop must be turned off starting from this point! This backup copy is your so-called insurance you can make use of in case of unexpected circumstances.

Have you ever transferred your Magento store to a new server? Welcome to share your experience in comments. If you're still afraid to switch to a new server yourself, drop us a line, and we'll be happy to help you!

Magento migration service from Amasty

December 17, 2014
December 18, 2014
November 10, 2014
Comments
Anastasia
May 21, 2015
Hello, I followed your steps and moved my Magento eshop to new server. Via the hosts file everything is working correctly , except that when I add a product to cart every page is a blank page. If I clear the cache, everything is back to normal. Have you ever encountered this problem? Regards, Anastasia
Reply
Ksenia Dobreva
May 21, 2015
Hi Anastasia, to know what exactly causes a blank page you need to check your server and Magento logs and to look for errors - you'll have more information then.
Anastasia
May 21, 2015
Hello Ksenia, I checked the logs but nothing it doesn't show anything regarding this error. Also another interesting thing.. I checked my eshop through this https://hosts.cx/ and everything is working correctly apart from the following: I add a product to the cart, product added successfully to cart. As long as I stay on the same page I can see my cart that has one product. When I navigate to another page the cart is empty. Also no errors is written either in the logs or in the console of the browser.
Ksenia Dobreva
May 22, 2015
Hey Anastasia, please check your email!
Billy Ross
February 10, 2016
Hi, I have moved my Magento shop to a new server before few days ago by following your procedure which you have mentioned above and i want to say that everything is working really well. So, want to say thanks to you for this useful information and please keep it up.
Reply
Ksenia Dobreva
February 10, 2016
Hi Billy, thanks for your comment, we're really glad the article was helpful for you!
Peter Maskolin
March 14, 2016
Hello I have finally move the my magento eshop for new server and everything is working correctly, Thanks
Reply
Ksenia Dobreva
March 14, 2016
Great! Glad the article was useful for you.
Robert Williams
June 22, 2016
Great article Ksenia. I successfully migrated my Magento website using your tips for which I can't thank you enough. I won't have to bother Rosehosting about migration now. Cheers.
Reply
Ksenia Dobreva
June 27, 2016
Hey Robert, thanks for reading! We're delighted that the article was helpful for you =)
Peter Miller
December 16, 2019
Hello I have finally move the my magento eshop . This blog has helped in understanding the points to consider while choosing to a new server. Thank you for sharing such important information.
Reply
Polina Litreyeva
December 20, 2019
Hi, Peter! Thanks for your feedback! We are glad that our blog is helpful to you.
saket
March 27, 2020
I m trying to do so with my magenta store but I don't know why its showing me 500 internal server error
Reply
Polina Litreyeva
March 30, 2020
Hi, Saket! Thanks for reading and for the question. Pity you’ve come up with the issue. You see, the question needs professional assistance with deeper insights into the system itself, as long as there are multiple reasons why the issue could occur in your store. Sorry but that is why we won’t help you in the comments. You can check the <a href="https://amasty.com/knowledge-base/how-to-fix-error-500-in-magento-2.html">article in our knowledge base</a> or <a href="https://amasty.com/magento-1-to-2-migration-service.html">contact us</a>, and we will help you with migration. Cheers!
Leave your comment

Your email address will not be published

This blog was created with Amasty Blog Pro

This blog was created with Amasty Blog Pro