How to Move Magento 2 from Localhost to Server

Steps to Move Magento 2 from Localhost to Server

Follow the following steps to move Magento 2 from localhost to server

  • Export Database from Localhost
  • Make Magento Files in Zip Format
  • Uploading Magento Files to Web Server
  • Import Database
  • Upload Magento Files
  • Change env.php file for Accessing the Magento System to New Database
  • Find Out your New Domain Name for Magento System
  • Run Commands

Export Database from Localhost

  • Turn on the localhost server like XAMPP, WAMP etc.
  • Login into the PhpMyAdmin.
  • Click on the database and then click on the Export button in PhpMyAdmin.
  • Click on the Go button to export the database. 

Make Magento Files in Zip Format

  • Select all the files and make a zip file.
  • If you are using the XAMPP server, open the htdocs folder.
  • If you are using the WAMP server, open the www folder.
  • Select the Magento folder that you want to move to the server and compress the folder in zip format. 

Uploading Magento Files to Web Server

  • Create a user and give access of database rights to the user.
  • You need to use cPanel to upload the database.
  • Login to the cPanel and open the PhpMyAdmin.
  • Create a new database.

Import Database

There are two methods to import the database, the first is you can import via command and the second method via PhpMyAdmin.

  • If you want to import a database via command then you can run this command:
mysql -p -u username database_name < backup_file.sql

If you are using the PhpMyAdmin to import then follow the steps.

  • Click on the Import button.
  • Click on the Choose File button to choose the database file from your directory.
  • Click on the Go button to process.

Upload Magento Files

  • Create the subfolder for the new domain. Or you can continue with the normal directory.
  • Extract the zip folder inside the subfolder.

Change env.php file for Accessing the Magento System to New Database

  • Open the app/etc/env.php.
  • In the env .php file change the information according to the new database like username, database name and password etc.

Find Out your New Domain Name for Magento System

  • Open the Core_Config_Data table of your database.
  • Find the “web/unsecure/base_url” and replace the localhost Url with the domain name.

Run Commands

Run the following commands:

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
php bin/magento cache:clean

 

If you want any kind of help please visit our Magento 2 Development Service and get a Quote.

 

Related Products