how to migrate WordPress from localhost to server

Migrating a WordPress site from localhost to a live server involves a series of steps designed to ensure that the shift is smooth and devoid of data loss or downtime. Whether you’re a developer who’s refined your site locally or you’re simply looking to make your development environment live, this guide will assist you through the process.

Pre-Migration Preparation

Backup Your Website: Begin by backing up your entire WordPress site from the localhost. This includes your website’s database, themes, plugins, media files, and any additional files created or modified.

Choose a Web Hosting Service: Select a reliable hosting provider that supports WordPress. Many offer 1-click-installation for WordPress, which can be useful for beginners but isn’t necessary for migration.

Domain Name: If you haven’t already, register a domain name that reflects your brand or business.

Step 1: Export the Local WordPress Database

Using phpMyAdmin in your local server software (like WAMP, MAMP, or XAMPP), you can export your database:

  1. Open phpMyAdmin.
  2. Select your WordPress database.
  3. Click on the ‘Export’ tab.
  4. Choose the ‘Quick’ method.
  5. Format should be set to ‘SQL’.
  6. Hit the ‘Go’ button, prompting you to download the SQL file.

Step 2: Upload WordPress Files to Live Server

You can upload your WordPress files to the live server using an FTP client (like FileZilla):

  1. Connect your FTP client to your hosting server using credentials provided by your hosting provider.
  2. Upload the files to the public_html (or similar) directory.
  3. Ensure you replace the server’s existing files with the files from your local server.

Step 3: Create a MySQL Database on Your Live Server

For your WordPress site to function on the live server, you need a database:

  1. Log into your hosting control panel (such as cPanel).
  2. Navigate to the ‘MySQL Database Wizard’ and create a new database.
  3. Assign a user to the database with full privileges.
  4. Note down the database name, username, and password.

Step 4: Import Your Local Database to the Live Server

Using phpMyAdmin in your hosting service:

  1. Access phpMyAdmin via your hosting account.
  2. Select your new database and navigate to the ‘Import’ tab.
  3. Choose your .sql file previously exported.
  4. Leave default settings and click ‘Go’ to import.

Step 5: Configure wp-config.php

Connect again via FTP and locate the wp-config.php file in the root directory:

  1. Edit the file to update the database name, user, and password.
  2. Ensure the database host value if necessary (typically ‘localhost’, but some hosts differ).
  3. Save the changes.

Step 6: Change Site URL

Since your site is moving from localhost to a new domain, the site URL needs to be updated:

  1. Access phpMyAdmin on your live server.
  2. Navigate to the wp_options table.
  3. Change the ‘siteurl’ and ‘home’ values to your new domain.

This can also be achieved through the wp-config.php by adding:

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

Step 7: Fix Permalinks

Upon completion of the migration, log in to your WordPress dashboard:

  1. Go to Settings > Permalinks.
  2. Note the current setting and then revert to ‘Plain’.
  3. Save changes and then switch it back to your preferred option.
  4. This refreshes the permalinks settings and ensures they function correctly on the live environment.

Step 8: Test Your Live Site

Thoroughly check your live site for any issues:

  • Make sure all the pages are loading without errors.
  • Check if all images and media are displaying correctly.
  • Ensure plugins are functioning correctly.

Troubleshooting Common Issues

Database Connection Errors: Double check wp-config.php settings. Ensure credentials are correct as per your live server details.

Broken Links or Missing Images: Ensure you’ve updated URLs everywhere. Consider using a tool like Velvet Blues Update URLs to automate the process.

Migrating a WordPress site is a comprehensive task requiring attention to detail. This guide covers all the critical stages, ensuring your site not only transfers over smoothly but is also set up correctly on your new server.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *