Home » Magento12 August 2013

Moving Magento from one server to another [Step-by-Step Guide]

Here is a step-by-step guide on moving Magento site from one server to another. This can be from localhost to server or from server to localhost or from one server to another.

Step 1: Enable maintenance mode

This is to be done so that no users could place any order while you are backing up your website data. After you enable maintenance mode, your website will not be accessible to users. They will see ‘Service not avaiable’ message.

To enable maintenance mode:

Create a file maintenance.flag on your website root folder.

Step 2: Backup files

You can copy all the files using FTP. However, there are thousands of files in Magento. If you have SSH access, then it will be quick to compress all the files and then download the compressed single file.

You can zip files using the following command on SSH:

zip -r archive_name.zip *

You can also use other compressions like tar, tar.gz, bz2, etc. See more: Linux commands to compress & extract files and folders

Step 3: Backup database

You can use phpMyAdmin to backup/export your database.

If you have SSH access, then you can use mysqldump command to backup your Magento database:

mysqldump -h hostname –u username –p password database_name > /path/backup.sql

You may also backup your database in compressed form:

mysqldump -h hostname –u username –p password database_name | gzip > /path/backup.sql.gz
mysqldump -h hostname –u username –p password database_name | bzip2 > /path/backup.sql.bz2

See more: MySQL: Backup and Restore database & table

Step 4: Upload files to new server

After you download all files and database backup from old server, you can now upload them into new server.

Step 5: Extract files

This step is not required if you have not compressed your files.

Extract your compressed Magento website files. You can do this through File Manager (Cpanel).

If you have SSH access then you can extract compressed file through the following command:

unzip archive_to_extract.zip

Step 6: Edit app/etc/local.xml

Edit app/etc/local.xml file and put correct mysql hostname, username, password, and database name.

Step 7: Adjust files and folders permission

You might get “Internal Server Error” if your Magento files and folders permission is not correct. All files should have 644 permission and folders should have 755 permission.

You can change the file and folder permission through FTP.

In SSH, you can do through the following commands:

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;

After that, you can adjust again the permission of ‘media‘, ‘var‘, and ‘app/etc‘ directory:

chmod -R 777 media var app/etc

Step 8: Import/Restore database in new server

Create a new database in the new server. Then you can import the database you have exported/backup from the old server with the help of phpMyAdmin.

If you have SSH access, you can restore/import database from the following command:

– Restore plain sql database file

mysql -h hostname –u username –p password db_name < /path/backup.sql- Restore database as gzip compressed file (Linux)gunzip < /path/backup.sql.gz | mysql -h localhost -u username -p database_name- Restore database as bzip2 compressed file (Linux)bunzip2 < /path/backup.sql.bz2 | mysql -h localhost -u username -p database_name

Step 9: Update base URL

You need to update base URL to your new website’s URL. In the below sql statement, change example.com to your new website URL.

UPDATE core_config_data SET value=”http://example.com/” WHERE path=”web/unsecure/base_url”;
UPDATE core_config_data SET value=”https://example.com/” WHERE path=”web/secure/base_url”;

You’re done.

Finally, you have moved/transferred your Magento website from one server/location to another.

One issue I faced while moving Magento site

After I completed the transfer of files and changed all the necessary settings in the new location, I got problem with the URLs of the site. SEO URL rewrite was not working properly even though mod_rewrite was enabled. URLs worked when I put index.php in them.

For example:
http://example.com/category (not working)
http://example.com/index.php/category (working)

The main cause to this problem was “missing .htaccess” file. Due to some reason, there was no .htaccess file in Magento root directory of the new site. I copied .htaccess from old site and added/uploaded the file and everything is working fine now.

Hope it helps. Thanks.


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Magento Developer

    In addition, it’s also good to have the data cleaning:
    rm -rf var/cache/*
    rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*
    rm -f downloader/pearlib/pear.ini

  • Rajeshwar Agrawal

    Hi Mukesk,
    Thanks for this excellent step by step guide. I have just one question in mind. In step 9, you have update the base url of website in the magento database. I am trying to use an architecture, where I can run multiple servers connected to a single DB server. Specifically, I want to use and AWS Autoscaling group along with ELB to start multiple EC2 instances, during high load. There is only one RDS Database instance. If I change the url as in step, then all the traffic will only go through a single ec2 instance. Is there any way in which we can have multiple ec2 instance serving a magento website.
    Thanks in advance.

  • Hi Mukesh, Thanks for step by step tutorial. I have shifted one of my magento store to a new host. Everything worked fine except, my theme’s stylesheet is not applying, although I can see the stylesheet file has been loaded and can access it through browser. But somehow it is not applying. thanks

  • Yawer Malik

    Its more easier with cloudways migration which is totally free and easy.