Moving a production site from one hosting environment to another can be a bit of a daunting task, even for a seasoned developer. It's a pretty straight forward process but there are a lot of moving parts, and the last thing you want to do is mess something up on an ecommerce site. Magento is a little mroe tricky than say, WooCommerce, or some more non-enterprise platforms.

Below is a outline of how to actual transfer the site and get up and going. I suggest before you even get to this point you take inventory of critical functionality, understand the DNS setup and ALL moving parts. This is just the actual moving of things!

1. First and foremost, Backup, backup, backup.

If you're moving to a specific Magento host (say Nexcess), I suggest running a backup there too, of the fresh install. Worse case you roll it back to what you started with after signing up.

You can empty out any logging and cache directories before you do this if you like. It will make the backup smaller and run faster.

Here are the folders you CAN (optional!!) empty.

  • var/log
  • var/cache
  • var/session
  • var/report

2. Create a database dump

Now that you have a physical file backup, let's grab a copy of the database.

mysqldump --single-transaction -u username -p database_name --triggers | sed -e 's/DEFINER[ ]=[ ][^]*/*/' | gzip > databasename.date +"%Y%m%d".sql.gz

3. Time to move your files

I suggest SCP to do this. It will be faster than downloading that backup, unpacking it, uploading the files and hoping your FTP client doesn't blow up. Because that happens. Often. Then you are kicked out of your session and have to try to log back in, only to be blocked or your session is still stuck and its at max limit for connections... you get the point. SSH/SCP is your friend.

Your command on the server you are moving FROM, will look something like this:

scp -r /public_html/* username@NEWhostname.com:/public_html

Need more info on SCP? Here is a good walkthrough on using SCP to move files.

Now you wait. It's going to take a bit because we are moving a ton of files. So go make some coffee and make sure your computer doesn't goto sleep while you're gone. 🙂

4A. Time to move your database

Guess what... same process, slightly different command.

scp -r /public_html/mysqldump.sql username@NEWhostname.com:/public_html

4B. Import your database

Now we're going to use mysql dump again to put our Magento database into place on the new server. You should no longer have a terminal open for the old server, or at least, not in your main window.

You should now be on the new host to do these next steps!

4C. Update your database settings

We're going to open /app/etc/local.xml as we may need to make hostname and/or username and password changes for Magento to connect to the database.

6. Double check your file permissions

We're going to want 644 on files and 755 for folders.

Reference this for more info on Magento filesystem permissions

7. URLs may need updated

More than likely you will need to do this. I'm going to assume you have not already switched DNS so you are using a temp url to test before deploying to production...right? 😉

We're going to edit core_config_data for this.

8. Test, test, test.

Then test some more. Since you took an inventory of all functionality before migrating, you should have a faux checklist to go through and make sure everything is working.

Some things in particular to look for:

  • Emails send
  • You can login, logout as a customer
  • You can login, logout as an Admin
  • You can checkout!
  • The site loads fast and does not have any console errors

9. Reindex

Now you need to reindex your data. Login and refresh all the caches and reindex catalog url rewrites.

10. You are done!

You may need to setup and change some DNS settings, but your actual migration is completed at this point and should be functioning as expected, since you tested it and re-ran all cache and indexes.

Posted by Drew Poland

Founder and Lead Developer of Spotfin Creative. WordPress Community Member.

Leave a Reply

Your email address will not be published. Required fields are marked *