Developing a website using a Local Server Environment is much more likely that everyone does in the field of Software Development. Needless to say it’ll save your time in running the files and testing it at greater speed that you do it on production server.
I’ve been using WordPress for most of my Client Projects and I wanted to write this post earlier as a diary note attached in my blog which might help the readers if they come here searching for something. Anyway, now that I’ve decided to go on with it, I will also might add the migration process from Localhost to Live Server with various CMS Platforms such as CS Cart, Magento later on continuing with this post.
The Migration can be done easily if you know a little bit of SQL Queries that needs to be played with., I assume that you here are capable of doing so very small of these following queries to your server database provided even for non-developers.
So, read below the steps to migrate your WordPress website from Localhost environment to Production Server environment.
STEP 1 :
Zip the files from your localhost server and also export the dump SQL file from the PHPMYADMIN.
STEP 2 :
Now Upload the zip file to your server and extract the files and make sure the files are placed inside ‘public_html’ folder in your server.
Assuming you’ve created the database through CPanel, now login to your server’s PHPMYADMIN, and import the dump SQL file to the created database.
STEP 3 :
Now, once the importing is done, go to SQL section and run the following queries.
UPDATE wp_options SET option_value = replace(option_value, 'http://localhost/yourwebsite', 'http://yourwebsite.com') WHERE option_name = 'home' OR option_name = 'siteurl';
The above query is to modify the website location that was once “http://localhost/yourwebsite” to “http://yourwebsite.com”
STEP 4 :
Now, we’ve to update the URLs of posts and pages.
Run the following query to update the same.
UPDATE wp_posts SET guid = replace(guid, 'http://localhost/yourwebsite','http://yourwebsite.com');
Now, if any of the posts, or pages are linked internally, the url has to be replaced with your live server url. So, run the below query to do that for you.
UPDATE wp_posts SET post_content = replace(post_content, 'http://localhost/yourwebsite', 'http://yourwebsite.com');
Now that everything is set, we just have to do one last thing and we’re all set to check the website.
STEP 6 :
Open up your wp-config.php file and replace the following values with your SQL Configuration.
define('DB_NAME', 'your-db-name'); /** MySQL database username */ define('DB_USER', 'your-server-username'); /** MySQL database password */ define('DB_PASSWORD', 'your-db-password');
We’re all set to check the website.
In some cases, the links in the website may not work , and if that happens, it is because of the pretty urls which needs to be changed and reverted back once to make sure all the urls are set.
Now to do that, we should login to the back end of the WordPress website WP-ADMIN and find “Settings” in the side menu bar.
Go to Settings -> Permalinks . The selected value would be “Post name”. Now we have to change it to “Plain” and save the settings. Now go to front end of the website and check all the links are working. If it is working, then you can go back to the Permalinks and revert back to “Post name”. Now the urls in your website are again back to the pretty urls configuration.
That’s it., you’ve successfully migrated your WordPress website from Localhost to Live Server without any issues.
P.S : Drop me a comment if you’ve any issues or problems in migration.
Image Credit : Flickr
If you want to read about Magento – Migration from Localhost to Live Server