Normally when developing a Magento site, you will work in Localhost environment like Xampp or Wamp before migrating your Magento site to a live server. In this tutorial, we will learn how to transfer our Magento site’s code and database from Localhost to a live hosting/server (Read our top 5 recommended hosting with Magento optimization).
There are 5 steps to be done as below:
- Export database of Magento site (SQL file)
- Upload code of Magento site to live server
- Import database to live server and change database configuration.
- Replace local URL with live site URL in database
- Pointing your domain to server’s IP
First we will export database of Magento to SQL file, open your PHPmyadmin program > Select the database you are using in Localhost for your Magento site. From Phpmyadmin menu, select Export, Choose Quick Export and click on Go to start exporting Database.
Now go to your Magento installation folder in Localhost, select all files/folder and upload it to your live server /www folder using an FTP/SFTP Client such as: Filezlla, Winscp, CuteFTP (when purchase a hosting or VPS, you will be provided with FTP/SFTP information)
Alternatively, If your server is using Cpanel, you can zip your Magento installation folder/files and upload it to www folder of your live server then select the .zip file and unzip it.
If you have ssh access to your server, unzip the file using linux command as below
yum install unzip
Now we will import database of our localhost to the live server.
Open your live server’s phpmyadmin tool and create a new database (Note username and password of the new database for future use)
Select the new database and click on Import from menu, now choose the .SQL file we got from step 1 to import.
If the import is successful, you will see this message
Import has been successfully finished, 331 queries executed. (magentodb.sql)
Next, open app/etc/local.xml on your live site and alter the follow lines:
DBUSERNAME: Username of the database
DBPASSWORD: Password of the database
DBNAME: Name of the database
Next we need to replace localhost URL with live site URL to make the live site work properly. Go to PHPmyadmin on your live server, and select your database using for Magento site.
Find the table core_config_data and edit url in column web/unsecure/base_url and web/secure/base_url to the domain of your live site
Finally clear Magento Cache by navigating to System > Cache management > Flush Magento cache or simply delete var/cache and var/session folders to make the website run properly
Pointing domain to your live server, login to your domain management section, for example godaddy, you will point your domain to your live site by create the following records:
Above are all steps needed to transfer/move a Magento store installation from localhost to Live environment, if you encounter any problems during the process, drop a comment here and I’ll be glad to help you out.