How to Move Magento to a New Server or Domain

Clone magento another hosting domainMagento is one of the fastest growing eCommerce platforms on the internet and with its recent acquisition by eBay it promises to stay on the lead and keep growing with even faster pace than before.  It’s been choice for a platform for many of my clients and recently I had to do some development work on one of the websites. The shop was running Magento 1.7 and was on a dedicated CentOS server.

Move Magento to different domain/subdomain

I had to copy the live site in a development environment do the changed and move back to the live instance. The structure was as follows:
[cc lang=”text”]Live instance:
Path: /var/www/vhosts/live

Dev Instance:
Path: /var/www/vhosts/dev[/cc]
so to start first I moved across all of the files from live to dev:
[cc lang=”text”]# cp -r /var/www/vhosts/live/* /var/www/vhosts/dev[/cc]
Next step was creating database for the development instance. First create your database in MySQL
[cc lang=”sql”]CREATE DATABASE magento_dev;[/cc]
Then you can copy the live one to the dev with one simple command:
[cc lang=”text” escaped=”true”]# mysqldump -umagento -p magento_live > mysql -umagento -p magento_dev[/cc]
OK so far so good we have the code base and the database ready next step would be changing the configurations of the development build so it uses the correct database connection. This step is very important and you should make sure that you dev build is not connected to your live database because this will mess the things up really bad.

The configuration file in our dev build is under: /var/www/vhosts/dev/app/etc/local.xml there you have to edit the following lines:
[cc lang=”xml” escaped=”true”]<host><![CDATA[HOSTNAME]]></host>
And those should have values according to your database and user in our case that was:
[cc lang=”xml” escaped=”true”]<host><![CDATA[localhost]]></host>
Once the database connection is established you have to change the base URL of the shop. There are two specific rows that needs to be updated and they should be in your config table: core_config_data
[cc lang=”sql”]UPDATE core_config_data SET value = “” WHERE path = “web/unsecure/base_url”;
UPDATE core_config_data SET value = “” WHERE path = “web/secure/base_url”;[/cc]
In our case the secure and insecure URLs are both the same but if you have HTTPS already set for the new domain you can change the second query to match your existing URL. We are almost done but most likely our shop still wont work and the reason for that is the Magento magical cache. You have to delete all file and session cache.
[cc lang=”text”]# rm -fr /var/www/vhosts/dev/var/cache/*
# rm -fr /var/www/vhosts/dev/var/session/*[/cc]
So that is all you can now start using you new shop. If you have problems logging in to Magento back-end because you don’t know the admin password you can restart Magento admin password.

Move Magento to another host

This is almost the same process but you need to compress the files and move them across to the other server.

First we have to export our database:
[cc lang=”text”]# cd /var/www/vhosts/live
# mysqldump -umagento -p magento_live > magento_live.sql[/cc]
After that move to the root folder that contains all of the live build files and archive it with tar ball
[cc lang=”text”]# tar -zcvf magento_live_bck.tar.gz /var/www/vhosts/live/*[/cc]
This archive should contain all of the Magento files and the database dump. Next step is copying the archive across to the other server:
[cc lang=”text”]# scp /var/www/vhosts/magento_live_bck.tar.gz
# cd /var/www/vhosts/live
# tar -zxvf magento_live_bck.tar.gz[/cc]
Once you have moved the files across all you have to do is import the database and do the steps mentioned above for the domain move.

Other issues with Magento blank screen

If you get blank screen check your php error log and enable your error printing by putting this into index.php
[cc lang=”php”]// index.php
Here is a solution of error that I go: Broken local XML
[cc lang=”text”]Call to a member function extend() on a non-object in httpdocs/lib/Varien/Simplexml/Config.php on line 600[/cc]
Other than that you should make sure you have all needed PHP extensions installed on the server for example mbcrypt.

And last but not least is to check your .htaccess file and if needed update the RewriteBase tag to point to your root directory on your server.


Just a guy with strong interest in PHP and Web technologies

Tagged with: , ,

Leave a Reply

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


This site uses Akismet to reduce spam. Learn how your comment data is processed.