After creating your dream Magento store on localhost when its time to move it to production server sometimes people get nervous. Its a piece of cake and we will help you in migrating your Magento store from localhost to production server.
Prerequisite
1. Working domain
2. Production ready for Magento
Working domain
By working domain means the domain on which you are going to host your store. For example https://mademo1.knowband.com
Production ready for Magento
It means there should be all the elements properly setup on the server which is required for a Magento to run. If you need any help regarding that then you can check the link https://www.knowband.com/blog/magento-tutorials/install-magento-using-command-line/
Steps for Migration
1. Export your localhost database
Export your localhost Magento store database. There are two ways of doing it
A) Via PhpMyAdmin
B) CLI
My personal favorite is via command line interface(CLI) as it is faster than the former one. We will see each way one by one.
a)PhpMyAdmin
Login to you PhpMyAdmin and go to your database. There you will see option “Export” in the header. Here “testmage1” is the name of my database.
Check the below image for reference
b) CLI
CLI or command line interface is better than PhpMyAdmin as it is faster.
mysqldump -u root -p testmage1 > database_name.sql
Put the name of you database in the place of testmage1. This command will create the dump of your database with the name database_name.sql
2. Compress and upload your Magento files
After the database has been exported now its time to compress your Magento store files. Create the zip of all the files of your store. This way it will be easy to upload it on the server. Now open Filezilla and upload the zipped file over the server and extract it in the required folder.
3. Import Database
Now its time to import your database on your production. Now again there are two ways of doing it
a) PhpMyAdmin
Login to your PhpMyAdmin of production and create an empty database with the same name as on your localhost. After creating a database you will see “Import” option in the header.
Check Image for reference.
After clicking on the Import browser you file as shown in the image and click on GO. This will take a few minutes and your database will be imported.
b) CLI
For importing database via CLI you need to upload your database file via FTP and login to your server via terminal. Use following command to import the database
mysql -u username -p database_name < file.sql
Here database_name is the name of the database in which your file will be imported and file.sql is the file which you are importing.
4. Modify local.xml
Now we need to modify our local.xml file so that our Magento can access the database. Open Magento_Root/app/etc/local.xml
In it search for <connection> node.
<host><![CDATA[host_name]]></host> <username><![CDATA[db_user_name]]></username> <password><![CDATA[db_password]]></password> <dbname><![CDATA[database_name]]></dbname>
Update these tags as per the production configuration. Your database connectivity is done now.
5. Update domain name
Now its time to make entry of domain name in the database. Open table core_config_data and update your domain in
1.web/unsecure/base_url
2.web/secure/base_url
as shown in the image.
6. Flush Cache
Now its time to refresh your cache as there might be some cache from your localhost machine. To refresh your cache go to
Magento_Root/var/cache
This folder contains your cache. Delete all the files and directory of this folder.
Now you are all set. Your Magento store has been successfully migrated from localhost to production server. Go to your web browser and enter your domain in address base and hit enter. Your website will open as it was in your localhost.
Bottomline
These are the steps to migrate your localhost Magento store to the production server. Always keep backup of your code and database in case anything goes wrong. If your website is not opening properly then go through the above-mentioned steps again and check if you missed anything. Happy Coding:)