Magento 2 store setup can be complicated. You may not want to offer a half baked setup to your potential customers only to disappoint them.
The solution is to first set up the Magento 2 store in localhost. You may have spent hours building your store. Once you finish implementing and configuring every feature, you can go LIVE!
Before moving to learn the steps, make sure you have purchased domain and best Magento hosting as well.
This post shows the method to move Magento 2 from localhost to server.
Steps to Move Magento 2 from Localhost to Server:
Step 1: Export Database from Localhost
- Connect to localhost software like XAMPP, WAMP etc and login to phpMyAdmin
- Visit the store’s database
- At the top of the menu, click Export then hit Go button.
Now, you will be able to download the database files as the .sql extension. You can also save it in .zip form.
Step 2: Make Magento Files in Zip Format
Select all the files and folders from localhost and make a zip file.
- Go to htdocs folder (if you are using XAMPP) or www folder (if WAMPP)
- Navigate to Magento folder and compress the files in zip format
Step 3: Uploading Magento Files to Web Server
For uploading database, you need to upload via cPanel that is your website server. But before that, you need to create a user and give database rights.
- Login to cPanel.
- Go to phpMyAdmin
- In phpMyAdmin, create a new database by clicking on the new button. Make sure you remember database name, username and password.
Step 4: Import Database
After creating a database, you need to import the database file which you have downloaded in step 1.
You can leverage two methods for importing the database.
The first method for importing the database is by using the command line.
mysql -p -u username database_name < backup_file.sql
The second method for importing the database is by using PHPMYADMIN.
- Find out the Import option at the top of the menu and click on it
- To import the database, hit Choose File and upload a file having .sql extension
Step 5: Upload Magento Files
You can also create a subfolder for a new domain. If you do not wish to do, you can continue with normal directory also.
Upload the zip file and extract that you created in step 3.
Step 6: Change env.php file for Accessing the Magento System to New Database
Once you finish uploading the zip folder with extraction, you will now need to make changes in env.php file.
Go to app/etc/env.php. In env.php file, you will have to make changes related to the information of the new database that you just created on your domain. Make changes in a username, name and password while importing the database to your new domain. Locate in the file where this information is suitable. You will find something like the below image.
Step 7: Find Out your New Domain Name for Magento System
After the completion of step 6, you need to make save the changes.
- Click Save in the top right
- If you wish to select and edit the file, you need to upload it again to the right directory. For that, go to the Magento database and search Table Core_Config_Data.
- Replace localhost URL to domain name in “web/unsecure/base_url”
Step 8: Run Below Commands
Run all the below commands and you will manage to access your Magento store.
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 need more help regarding this post, feel free to ask in the Comment section below.
I would be happy to help you.
Share this post with Magento Community via social media.
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.