In this tutorial, I instruct you how to migrate wordpress website from localhost to hosting provider.
First, go to your host via FTP, delete all unnecessary folders and files in the public_html directory to avoid trouble later.
Some tips before moving the website from localhost to the host
- You must disable the cache-enabled plugins like WP Super Cache, W3 Total Cache
- The domain name must be point to the host.
- Make sure your website at localhost does not have too much data because the more data, the more plugins will be have problem.
Step 1. Compress the WordPress directory at localhost to .zip
Now go to localhost in your C:\xampp\htdocs\directory, select all the directories and files in it -> right click -> Send to -> Compressed (zip )
You will get a .zip file containing the website files and directories, you can rename the file to whatever you like
Step 2. Upload and extract on the host
Next, log in to the host’s control panel, go to File Manager and upload the website.zip archive file to the root directory (public_html) if you need to use the website with the root domain name http: // domain-name- of -your web site/, if you want to install it into a specific directory like http: //my-domain.com / directory / then create one and upload it.
After upload, you right-click on the .zip file and select Extract.
After extract, you will have WordPress folders and files on the host like this.
Step 3. Export the database at localhost
Next you nee create a database on the host and visit phpMyAdmin on localhost at http://localhost/phpMyAdmin and select the database that you have installed WordPress on localhost on.
Then select Export and press Go.
You will have a file with the extension .sql, which is the file containing the entire database of your website.
Step 4. Import database into hosting
Go to the host’s control panel and navigate to the phpMyAdmin section.
Then select the database you just created (this database must be completely new).
Then select Import, upload the .sql file on your computer, leave the other settings as they are and press Go.
Step 5. Edit the WordPress configuration file
Because at localhost, we have installed the WordPress website with database information completely different from the database information on the host, so we have to fix that information to match the database information on the host before the website can run.
Login to FTP with FileZilla, go to the directory containing the WordPress website source code and navigate to the file named wp-config.php and open it.
Then you insert the following below <? php in the wp-config.php file:
Remember to replace example.com with the domain name you added to the host, my example is designthing.net
Continue to find the DB_NAME segment, fix the value in the back pair ” into your database name on the host, search for DB_USER and fix its value in the back sign ” into the username of the database on the host, find DB_PASSWORD and fix the value in the double quotation marks behind it into the password of the database username. All values must be written in quotation marks.
As for DB_HOST, most of the time we write it as localhost, except for some particular host providers, they will use a different but different Database Host name.
After editing, save this file, close the file window and you’ll see it asks if you want to upload it again, press Yes.
The process is completed, now try to access the Dashboard address of WordPress website at http: //my-domain.com/wp-admin and log in. Then go to Settings -> Permalinks and press the Save Change button so it updates permalink if you have it set, otherwise it will get 404 errors when viewing posts and pages.
If you come to the website and get an error “Error establishing a database connection” means that you entered the wrong database information, please check the information and enter it correctly.
Replace the old domain name at localhost to the new domain name
When you make a website at localhost, the links like the image in the article all have the domain name at localhost, so only you can see it. Our task is to replace the old domain name at localhost into the official domain name of the website through a plugin.
Find and install the plugin named Better Search Replace and activate it. Next, go to Tools -> Better Search Replace.
In the Search for box, enter the string to search, the string here is your old domain name on localhost, my example is designthing.local. In the Replace with section, enter the string to be replaced, that is, the official domain name used for the website, my example is designthing.net. At the table, press Ctrl + A to select all the tables in the database, uncheck the Run as dry run section, and then click Run.
Now you can start developing your website officially.