WordPress Migration – Localhost to a Live Server: A Step-by-Step Guide

WordPress Migration – Localhost to a Live Server: A Step-by-Step Guide

When developing a website, using a local server environment is a common practice among software developers. It allows you to work on your site offline, making changes and testing them quickly without affecting a live site. This approach can save significant time and streamline the development process.

In this post, I’ll guide you through the process of migrating your WordPress website from a local server (localhost) to a live production server. This tutorial will be useful if you’re transitioning your website from a development environment to a public-facing site. I’ll also touch on migration techniques for other CMS platforms like CS Cart and Magento in future posts.

Why Migrate from Localhost to a Live Server?

Migrating from a local server to a live server allows you to make your website accessible to the public. It also enables you to test the website in a real-world environment, where factors like server speed, security, and accessibility come into play.

Prerequisites

Before you start the migration, ensure you have:

  • Database access on your live server (e.g., through cPanel or phpMyAdmin).
  • Access to both your local server and live server environments.
  • A WordPress installation on your local server.
  • FTP access or file manager access to your live server.

Migration Steps

Step 1: Export Local Files and Database
  1. Export the Database:
    • Access your local phpMyAdmin.
    • Select your WordPress database.
    • Click on the “Export” tab.
    • Choose the “Quick” export method and format “SQL”.
    • Click “Go” to download the SQL file.
  2. Zip Your Local Files:
    • Compress your WordPress files (including themes, plugins, and uploads) into a ZIP archive.
Step 2: Upload Files to the Live Server
  1. Upload the ZIP Archive:
    • Connect to your live server using FTP or your hosting provider’s file manager.
    • Upload the ZIP archive to the root directory (typically public_html).
  2. Extract the Files:
    • Extract the ZIP file on your server, ensuring all files are in the public_html directory.
  3. Import the Database:
    • Create a new database on your live server through cPanel or your hosting provider’s database management tool.
    • Access phpMyAdmin on your live server.
    • Select the newly created database.
    • Click on the “Import” tab.
    • Upload the SQL file you exported earlier and click “Go”.
Step 3: Update Database URLs
  1. Update Site URL:
    • In phpMyAdmin, select the database and navigate to the SQL tab.

Run the following query to update the WordPress site URL:

UPDATE wp_options SET option_value = REPLACE(option_value, 'http://localhost/yourwebsite', 'http://yourwebsite.com') WHERE option_name = 'home' OR option_name = 'siteurl';
  1. Update Post URLs:

Run this query to update the URLs in the posts:

UPDATE wp_posts SET guid = REPLACE(guid, 'http://localhost/yourwebsite', 'http://yourwebsite.com');
  1. Update Internal Links:

Run this query to update internal links within posts and pages:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://localhost/yourwebsite', 'http://yourwebsite.com');
Step 4: Update wp-config.php
  1. Configure Database Connection:
    • Open the wp-config.php file in your live server’s root directory.

Update the database connection details:

define('DB_NAME', 'your-db-name');
define('DB_USER', 'your-server-username');
define('DB_PASSWORD', 'your-db-password');
Step 5: Fix Permalinks
  1. Update Permalinks Structure:
    • Log in to the WordPress admin dashboard.
    • Navigate to Settings > Permalinks.
    • Temporarily change the permalink structure to “Plain” and save changes.
    • Check the frontend of your website to ensure all links are working.
    • Revert to the “Post name” structure and save changes again.

This step ensures that WordPress regenerates its permalink structure, fixing any broken links.

Conclusion

Your WordPress website should now be successfully migrated from localhost to a live server. If you encounter any issues or if something doesn’t seem to be working correctly, don’t hesitate to leave a comment below, and I’ll do my best to help you out.

Credits :
Photo by Choong Deng Xiang on Unsplash